ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file

Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
Henry Weller
2016-05-30 21:20:56 +01:00
parent 1cce60aa78
commit eba760a6d6
24640 changed files with 6366069 additions and 0 deletions

View File

@ -0,0 +1,65 @@
#==========================================================================
#
# Program: ParaView
#
# Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
# All rights reserved.
#
# ParaView is a free software; you can redistribute it and/or modify it
# under the terms of the ParaView license version 1.2.
#
# See License_v1.2.txt for the full ParaView license.
# A copy of this license can be obtained by contacting
# Kitware Inc.
# 28 Corporate Drive
# Clifton Park, NY 12065
# USA
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#==========================================================================
set (Module_SRCS
CPythonAdaptorAPI.cxx
vtkCPPythonAdaptorAPI.cxx
vtkCPPythonScriptPipeline.cxx
)
set_source_files_properties(
vtkCPPythonAdaptorAPI
ABSTRACT)
set (${vtk-module}_HDRS CPythonAdaptorAPI.h)
set (CATALYST_FORTRAN_USING_MANGLING)
if (CMAKE_Fortran_COMPILER_WORKS)
include(FortranCInterface)
FortranCInterface_HEADER(FortranPythonAdaptorAPIMangling.h
SYMBOLS coprocessorinitializewithpython coprocessoraddpythonscript)
set(CATALYST_FORTRAN_USING_MANGLING ${FortranCInterface_GLOBAL_FOUND})
set (Module_SRCS
${Module_SRCS}
FortranPythonAdaptorAPI.cxx)
set (${vtk-module}_HDRS
${${vtk-module}_HDRS}
FortranPythonAdaptorAPI.h
${CMAKE_CURRENT_BINARY_DIR}/FortranPythonAdaptorAPIMangling.h)
endif()
vtk_module_library(${vtk-module} ${Module_SRCS})
target_link_libraries(${vtk-module} LINK_PRIVATE vtkUtilitiesPythonInitializer)
if (CATALYST_FORTRAN_USING_MANGLING)
set_property(TARGET ${vtk-module} APPEND PROPERTY COMPILE_DEFINITIONS
"CATALYST_FORTRAN_USING_MANGLING=1")
endif()

View File

@ -0,0 +1,49 @@
/*=========================================================================
Program: ParaView
Module: CPythonAdaptorAPI.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "CPythonAdaptorAPI.h"
#include "vtkCPProcessor.h"
#include "vtkCPPythonAdaptorAPI.h"
#include "vtkCPPythonScriptPipeline.h"
void coprocessorinitializewithpython(
char* pythonFileName, int* pythonFileNameLength)
{
vtkCPPythonAdaptorAPI::CoProcessorInitialize(NULL);
if(pythonFileName != NULL || *pythonFileNameLength > 0)
{ // we put in a check here so that we avoid the warning below
coprocessoraddpythonscript(pythonFileName, pythonFileNameLength);
}
}
void coprocessoraddpythonscript(
char* pythonFileName, int* pythonFileNameLength)
{
if(pythonFileName == NULL || *pythonFileNameLength == 0)
{
vtkGenericWarningMacro("Bad Python file name or length.");
return;
}
int length = *pythonFileNameLength;
char *cPythonFileName = new char[length + 1];
memcpy(cPythonFileName, pythonFileName, sizeof(char)* length);
cPythonFileName[length] = 0;
vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New();
pipeline->Initialize(cPythonFileName);
vtkCPPythonAdaptorAPI::GetCoProcessor()->AddPipeline(pipeline);
pipeline->FastDelete();
}

View File

@ -0,0 +1,49 @@
/*=========================================================================
Program: ParaView
Module: CPythonAdaptorAPI.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef CPythonAdaptorAPI_h
#define CPythonAdaptorAPI_h
#include "vtkPVPythonCatalystModule.h"
#include "CAdaptorAPI.h"
// This code is meant to be used as an API for C simulation
// codes. To use with C codes, include this header file. Call the
// 'extern "C"' functions as named below for both Fortran and C.
// C code should include this header file to get the properly
// mangled function names. This extends CAdaptorAPI.h to add a new
// initialization function that takes a Python script and another
// function to add in extra Python scripts. Note that
// coprocessorinitializewithpython() isn't required to contain
// a Python script.
#ifdef __cplusplus
extern "C" {
#endif
// call at the start of the simulation
void VTKPVPYTHONCATALYST_EXPORT coprocessorinitializewithpython(
char* pythonFileName, int* pythonFileNameLength);
// add in another Catalyst Python pipeline script.
void VTKPVPYTHONCATALYST_EXPORT coprocessoraddpythonscript(
char* pythonFileName, int* pythonFileNameLength);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
// VTK-HeaderTest-Exclude: CPythonAdaptorAPI.h

View File

@ -0,0 +1,23 @@
/*=========================================================================
Program: ParaView
Module: FortranPythonAdaptorAPI.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// CATALYST_FORTRAN_USING_MANGLING is defined when Fortran names are mangled. If
// not, then we don't add another implementation for the API routes thus avoid
// duplicate implementations.
#ifdef CATALYST_FORTRAN_USING_MANGLING
#include "FortranPythonAdaptorAPI.h"
#include "CPythonAdaptorAPI.cxx"
#endif

View File

@ -0,0 +1,30 @@
/*=========================================================================
Program: ParaView
Module: FortranPythonAdaptorAPI.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef FortranAdaptorAPI_h
#define FortranAdaptorAPI_h
#include "vtkPVPythonCatalystModule.h"
#include "FortranPythonAdaptorAPIMangling.h"
// This code is meant to be used as an API for C simulation
// codes. To use with C codes, include this header file. Call the
// 'extern "C"' functions as named below for both Fortran and C.
// C code should include this header file to get the properly
// mangled function names.
#include "CPythonAdaptorAPI.h"
#endif
// VTK-HeaderTest-Exclude: FortranPythonAdaptorAPI.h

View File

@ -0,0 +1,204 @@
include_directories(
${TestDriver_SOURCE_DIR})
set(CP_LABELS PARAVIEW CATALYST)
#------------------------------------------------------------------------------
vtk_module_test_executable(CoProcessingPythonScriptExample
PythonScriptCoProcessingExample.cxx
vtkPVCustomTestDriver.cxx)
#------------------------------------------------------------------------------
# Generate the image compare tool.
# below is for doing image comparisons
vtk_module_test_executable(CoProcessingCompareImagesTester CompareImages.cxx)
#------------------------------------------------------------------------------
# a simple test to see if the input is changing, i.e. that the initial
# pipeline is having it's trivial producer updated with a new grid
add_test(NAME CoProcessingTestInput
COMMAND pvbatch -sym ${CMAKE_CURRENT_SOURCE_DIR}/waveletdriver.py
${CMAKE_CURRENT_SOURCE_DIR}/TestInput.py 4
)
set_tests_properties(CoProcessingTestInput PROPERTIES LABELS "${CP_LABELS}")
# the CoProcessingTestPythonScript needs to be run with ${MPIEXEC} if
# CoProcessingPythonScriptExample was built with MPI because certain
# machines only allow running MPI programs with the proper ${MPIEXEC}
# just test if a given Catalyst Python script can import another script
if (NOT PARAVIEW_USE_MPI)
add_test(NAME CoProcessingImport
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/cpimport.py
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
else()
add_test(NAME CoProcessingImport
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/cpimport.py
-DUSE_MPI:BOOL=TRUE
-DMPIEXEC:FILEPATH=${MPIEXEC}
-DMPIEXEC_NUMPROC_FLAG:STRING=${MPIEXEC_NUMPROC_FLAG}
-DMPIEXEC_NUMPROCS=2
-DMPIEXEC_PREFLAGS:STRING=${MPIEXEC_PREFLAGS}
-DVTK_MPI_POSTFLAGS:STRING=${VTK_MPI_POSTFLAGS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
endif()
set_tests_properties(CoProcessingImport PROPERTIES LABELS "${CP_LABELS}")
# test if we can use a Python programmable filter in a Catalyst Python script
if (NOT PARAVIEW_USE_MPI)
add_test(NAME CoProcessingProgrammableFilter
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/cpprogrammablefilter.py
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
else()
add_test(NAME CoProcessingProgrammableFilter
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/cpprogrammablefilter.py
-DUSE_MPI:BOOL=TRUE
-DMPIEXEC:FILEPATH=${MPIEXEC}
-DMPIEXEC_NUMPROC_FLAG:STRING=${MPIEXEC_NUMPROC_FLAG}
-DMPIEXEC_NUMPROCS=2
-DMPIEXEC_PREFLAGS:STRING=${MPIEXEC_PREFLAGS}
-DVTK_MPI_POSTFLAGS:STRING=${VTK_MPI_POSTFLAGS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
endif()
set_tests_properties(CoProcessingProgrammableFilter PROPERTIES LABELS "${CP_LABELS}")
#- add_test(NAME CoProcessingProgrammableFilter
#- COMMAND CoProcessingProgrammableFilter
#- ${CMAKE_CURRENT_SOURCE_DIR}/cpprogrammablefilter.py)
if (NOT PARAVIEW_USE_MPI)
add_test(NAME CoProcessingTestPythonScript
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_IMAGE_TESTER:FILEPATH=$<TARGET_FILE:CoProcessingCompareImagesTester>
-DCOPROCESSING_DATA_DIR:PATH=${PARAVIEW_TEST_OUTPUT_BASELINE_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/PythonScriptTest.py
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
else()
vtk_mpi_link(CoProcessingPythonScriptExample)
add_test(NAME CoProcessingTestPythonScript
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_IMAGE_TESTER:FILEPATH=$<TARGET_FILE:CoProcessingCompareImagesTester>
-DCOPROCESSING_DATA_DIR:PATH=${PARAVIEW_TEST_OUTPUT_BASELINE_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/PythonScriptTest.py
-DUSE_MPI:BOOL=TRUE
-DMPIEXEC:FILEPATH=${MPIEXEC}
-DMPIEXEC_NUMPROC_FLAG:STRING=${MPIEXEC_NUMPROC_FLAG}
-DMPIEXEC_NUMPROCS=1
-DMPIEXEC_PREFLAGS:STRING=${MPIEXEC_PREFLAGS}
-DVTK_MPI_POSTFLAGS:STRING=${VTK_MPI_POSTFLAGS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
endif()
set_tests_properties(CoProcessingTestPythonScript PROPERTIES LABELS "${CP_LABELS}")
if (PARAVIEW_USE_MPI)
add_test(NAME PCoProcessingTestPythonScript
COMMAND ${CMAKE_COMMAND}
-DCOPROCESSING_TEST_DRIVER:FILEPATH=$<TARGET_FILE:CoProcessingPythonScriptExample>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_OUTPUT_DIR}
-DCOPROCESSING_IMAGE_TESTER:FILEPATH=$<TARGET_FILE:CoProcessingCompareImagesTester>
-DCOPROCESSING_DATA_DIR:PATH=${PARAVIEW_TEST_OUTPUT_BASELINE_DIR}
-DCOPROCESSING_TEST_SCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/PythonScriptTest.py
-DUSE_MPI:BOOL=TRUE
-DMPIEXEC:FILEPATH=${MPIEXEC}
-DMPIEXEC_NUMPROC_FLAG:STRING=${MPIEXEC_NUMPROC_FLAG}
-DMPIEXEC_NUMPROCS=2
-DMPIEXEC_PREFLAGS:STRING=${MPIEXEC_PREFLAGS}
-DVTK_MPI_POSTFLAGS:STRING=${VTK_MPI_POSTFLAGS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingTestPythonScript.cmake)
# both the parallel and the serial tests create the same output images
# so we run this one serially so that they don't interfere.
set_tests_properties(PCoProcessingTestPythonScript PROPERTIES RUN_SERIAL ON)
set_tests_properties(PCoProcessingTestPythonScript PROPERTIES LABELS "${CP_LABELS}")
endif()
if (PARAVIEW_BUILD_QT_GUI)
# for now the full workflow test only works with the shared lib builds of
# paraview since the static build will load all of the plugins automatically
# which will add in extra properties to objects in the created script
# which can't be used when running the 'simulation' since those same
# plugins won't be loaded then.
IF ( BUILD_SHARED_LIBS )
add_test(NAME CoProcessingFullWorkflow
COMMAND ${CMAKE_COMMAND}
-DPARAVIEW_EXECUTABLE:FILEPATH=$<TARGET_FILE:paraview>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_DIR}
-DPARAVIEW_TEST_XML:FILEPATH=${ParaView_SOURCE_DIR}/Plugins/CatalystScriptGenerator/Testing/CatalystGUI.xml
-DPVBATCH_EXECUTABLE:FILEPATH=$<TARGET_FILE:pvbatch>
-DCOPROCESSING_DRIVER_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/waveletdriver.py
-DCOPROCESSING_IMAGE_TESTER:FILEPATH=$<TARGET_FILE:CoProcessingCompareImagesTester>
-DCOPROCESSING_DATA_DIR:PATH=${PARAVIEW_TEST_OUTPUT_BASELINE_DIR}
-DCOPROCESSING_OUTPUTCHECK_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/outputcheck.py
-DTEST_NAME:STRING=CoProcessingFullWorkflow
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingFullWorkflowTest.cmake)
set_tests_properties(CoProcessingFullWorkflow PROPERTIES RUN_SERIAL ON)
set_tests_properties(CoProcessingFullWorkflow PROPERTIES LABELS "${CP_LABELS}")
ExternalData_add_test(ParaViewData NAME CoProcessingFullWorkflowWithPlots
COMMAND ${CMAKE_COMMAND}
-DPARAVIEW_EXECUTABLE:FILEPATH=$<TARGET_FILE:paraview>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_DIR}
-DPARAVIEW_TEST_XML:FILEPATH=${ParaView_SOURCE_DIR}/Plugins/CatalystScriptGenerator/Testing/CatalystGUIPlots.xml
-DPVBATCH_EXECUTABLE:FILEPATH=$<TARGET_FILE:pvbatch>
-DCOPROCESSING_DRIVER_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/waveletdriver.py
-DCOPROCESSING_IMAGE_TESTER:FILEPATH=$<TARGET_FILE:CoProcessingCompareImagesTester>
-DCOPROCESSING_DATA_DIR:PATH=${PARAVIEW_TEST_OUTPUT_BASELINE_DIR}
-DCOPROCESSING_OUTPUTCHECK_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/outputcheck.py
-DTEST_NAME:STRING=CoProcessingFullWorkflowWithPlots
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingFullWorkflowTest.cmake
DATA{${PARAVIEW_TEST_BASELINE_DIR}/CPFullWorkflowPlot1.png}
DATA{${PARAVIEW_TEST_BASELINE_DIR}/CPFullWorkflowPlot2.png} )
set_tests_properties(CoProcessingFullWorkflowWithPlots PROPERTIES RUN_SERIAL ON)
set_tests_properties(CoProcessingFullWorkflowWithPlots PROPERTIES LABELS "${CP_LABELS}")
find_python_module(numpy numpy_found)
if (numpy_found)
add_test(NAME CoProcessingFullWorkflowCinema
COMMAND ${CMAKE_COMMAND}
-DPARAVIEW_EXECUTABLE:FILEPATH=$<TARGET_FILE:paraview>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_DIR}
-DPARAVIEW_TEST_XML:FILEPATH=${ParaView_SOURCE_DIR}/Plugins/CatalystScriptGenerator/Testing/CatalystCinemaGUI.xml
-DPVBATCH_EXECUTABLE:FILEPATH=$<TARGET_FILE:pvbatch>
-DCOPROCESSING_DRIVER_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/waveletdriver.py
-DTEST_NAME:STRING=CoProcessingFullWorkflowCinema
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingFullWorkflowTest.cmake)
set_tests_properties(CoProcessingFullWorkflowCinema PROPERTIES RUN_SERIAL ON)
set_tests_properties(CoProcessingFullWorkflowCinema PROPERTIES LABELS "${CP_LABELS}")
endif()
find_python_module(numpy numpy_found)
if (numpy_found)
add_test(NAME CoProcessingFullWorkflowCinemaComposite
COMMAND ${CMAKE_COMMAND}
-DPARAVIEW_EXECUTABLE:FILEPATH=$<TARGET_FILE:paraview>
-DCOPROCESSING_TEST_DIR:PATH=${PARAVIEW_TEST_DIR}
-DPARAVIEW_TEST_XML:FILEPATH=${ParaView_SOURCE_DIR}/Plugins/CatalystScriptGenerator/Testing/CatalystCinemaCompositeGUI.xml
-DPVBATCH_EXECUTABLE:FILEPATH=$<TARGET_FILE:pvbatch>
-DCOPROCESSING_DRIVER_SCRIPT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/waveletdriver.py
-DTEST_NAME:STRING=CoProcessingFullWorkflowCinemaComposite
-P ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessingFullWorkflowTest.cmake)
set_tests_properties(CoProcessingFullWorkflowCinemaComposite PROPERTIES RUN_SERIAL ON)
set_tests_properties(CoProcessingFullWorkflowCinemaComposite PROPERTIES LABELS "${CP_LABELS}")
endif()
ENDIF ()
endif()

View File

@ -0,0 +1,129 @@
# CoProcessing test expects the following arguments to be passed to cmake using
# -DFoo=BAR arguments.
# PARAVIEW_EXECUTABLE -- path to paraview
# COPROCESSING_TEST_DIR -- path to temporary dir
# PARAVIEW_TEST_XML -- xml to run
# PVBATCH_EXECUTABLE -- path to pvbatch
# COPROCESSING_DRIVER_SCRIPT -- driver py script
# COPROCESSING_IMAGE_TESTER -- path to CoProcessingCompareImagesTester
# COPROCESSING_DATA_DIR -- path to data dir for baselines
# COPROCESSING_OUTPUTCHECK_SCRIPT -- path to outputcheck.py
# TEST_NAME -- a string to specify which results to test
macro(execute_process_with_echo)
set (_cmd)
foreach (arg ${ARGV})
set (_cmd "${_cmd} ${arg}")
endforeach()
message(STATUS "Executing command: \n ${_cmd}")
execute_process(${ARGV})
endmacro()
file(REMOVE
"${COPROCESSING_TEST_DIR}/cptest.py"
"${COPROCESSING_TEST_DIR}/cpplottest.py"
"${COPROCESSING_TEST_DIR}/image_0.png"
"${COPROCESSING_TEST_DIR}/image_0_0.png"
"${COPROCESSING_TEST_DIR}/image_1_0.png"
"${COPROCESSING_TEST_DIR}/filename_0.pvtp"
"${COPROCESSING_TEST_DIR}/filename_0_0.vtp"
"${COPROCESSING_TEST_DIR}/cinema")
if (NOT EXISTS "${PARAVIEW_EXECUTABLE}")
message(FATAL_ERROR "Could not file ParaView '${PARAVIEW_EXECUTABLE}'")
endif()
execute_process_with_echo(COMMAND
${PARAVIEW_EXECUTABLE} -dr
--test-plugin=CatalystScriptGeneratorPlugin
--test-directory=${COPROCESSING_TEST_DIR}
--test-script=${PARAVIEW_TEST_XML}
--exit
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "ParaView return value was ${rv}")
endif()
if(NOT EXISTS "${PVBATCH_EXECUTABLE}")
message(FATAL_ERROR "'${PVBATCH_EXECUTABLE}' does not exist")
endif()
message("Running pvbatch")
execute_process_with_echo(COMMAND
${PVBATCH_EXECUTABLE} -sym -dr
${COPROCESSING_DRIVER_SCRIPT}
${COPROCESSING_TEST_DIR}/cptest.py 1
WORKING_DIRECTORY ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "pvbatch return value was = '${rv}' ")
endif()
if("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflowCinema")
if(NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/image/info.json" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/image/0.000000e+00/-180/-180.png" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/image/0.000000e+00/-180/60.png" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/image/0.000000e+00/60/-180.png" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/image/0.000000e+00/60/60.png")
message(FATAL_ERROR "Catalyst did not generate a cinema store")
endif()
return()
endif()
if("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflowCinemaComposite")
if(NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/composite_image/info.json" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/composite_image/0.000000e+00_-180_-180/vis=Slice1/Slice1=0.0/colorSlice1=RTData_0.png" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/composite_image/0.000000e+00_-180_60/vis=Slice1/Slice1=0.0/colorSlice1=depth.im" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/composite_image/0.000000e+00_60_-180/vis=Slice1/Slice1=0.0/colorSlice1=luminance.png" OR
NOT EXISTS "${COPROCESSING_TEST_DIR}/cinema/composite_image/0.000000e+00_60_-180/vis=Slice1/Slice1=0.0/colorSlice1=RTData_0.png")
message(FATAL_ERROR "Catalyst did not generate a composite cinema store!")
endif()
return()
endif()
if(NOT EXISTS "${COPROCESSING_IMAGE_TESTER}")
message(FATAL_ERROR "'${COPROCESSING_IMAGE_TESTER}' does not exist")
endif()
if("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflow")
message("${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_0.png -V
${COPROCESSING_DATA_DIR}/CPFullWorkflow.png -T
${COPROCESSING_TEST_DIR}")
execute_process_with_echo(COMMAND
${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_0.png 40 -V ${COPROCESSING_DATA_DIR}/CPFullWorkflow.png -T ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "CoProcessingCompareImageTester return value was = '${rv}' ")
endif()
execute_process_with_echo(COMMAND
${PVBATCH_EXECUTABLE} -dr
${COPROCESSING_OUTPUTCHECK_SCRIPT}
${COPROCESSING_TEST_DIR}/filename_0.pvtp
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "vtkpython return value was = '${rv}' ")
endif()
endif("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflow")
if("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflowWithPlots")
message("${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_0_0.png -V
${COPROCESSING_DATA_DIR}/CPFullWorkflowPlot1.png -T
${COPROCESSING_TEST_DIR}")
execute_process_with_echo(COMMAND
${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_0_0.png 20 -V ${COPROCESSING_DATA_DIR}/CPFullWorkflowPlot1.png -T ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "CoProcessingCompareImageTester first image return value was = '${rv}' ")
endif()
message("${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_0_1.png -V
${COPROCESSING_DATA_DIR}/CPFullWorkflowPlot2.png -T
${COPROCESSING_TEST_DIR}")
execute_process_with_echo(COMMAND
${COPROCESSING_IMAGE_TESTER} ${COPROCESSING_TEST_DIR}/image_1_0.png 40 -V ${COPROCESSING_DATA_DIR}/CPFullWorkflowPlot2.png -T ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
if(rv)
message(FATAL_ERROR "CoProcessingCompareImageTester second image return value was = '${rv}' ")
endif()
endif("${TEST_NAME}" STREQUAL "CoProcessingFullWorkflowWithPlots")

View File

@ -0,0 +1,70 @@
# CoProcessing test expects the following arguments to be passed to cmake using
# -DFoo=BAR arguments.
# COPROCESSING_TEST_DRIVER -- path to CoProcessingPythonScriptExample
# COPROCESSING_TEST_DIR -- path to temporary dir
# COPROCESSING_TEST_SCRIPT -- python script to run
# COPROCESSING_IMAGE_TESTER -- path to CoProcessingCompareImagesTester
# COPROCESSING_DATA_DIR -- path to data dir for baselines
# USE_MPI
# MPIEXEC
# MPIEXEC_NUMPROC_FLAG
# MPIEXEC_NUMPROCS
# MPIEXEC_PREFLAGS
# VTK_MPI_POSTFLAGS
# remove result files generated by the test
file(REMOVE "${COPROCESSING_TEST_DIR}/CPPressure0.png" )
file(REMOVE "${COPROCESSING_TEST_DIR}/CPGrid0.png" )
if(NOT EXISTS "${COPROCESSING_TEST_DRIVER}")
message(FATAL_ERROR "'${COPROCESSING_TEST_DRIVER}' does not exist")
endif()
if (USE_MPI)
message("Executing :
${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_NUMPROCS} ${MPIEXEC_PREFLAGS}
\"${COPROCESSING_TEST_DRIVER}\"
\"${COPROCESSING_TEST_SCRIPT}\"")
execute_process(COMMAND
${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_NUMPROCS} ${MPIEXEC_PREFLAGS}
"${COPROCESSING_TEST_DRIVER}"
"${COPROCESSING_TEST_SCRIPT}"
WORKING_DIRECTORY ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
else()
message("Executing : \"${COPROCESSING_TEST_DRIVER}\" \"${COPROCESSING_TEST_SCRIPT}\"")
execute_process(COMMAND "${COPROCESSING_TEST_DRIVER}" "${COPROCESSING_TEST_SCRIPT}"
WORKING_DIRECTORY ${COPROCESSING_TEST_DIR}
RESULT_VARIABLE rv)
endif()
if(NOT rv EQUAL 0)
message(FATAL_ERROR "Test executable return value was ${rv}")
endif()
if(EXISTS "${COPROCESSING_IMAGE_TESTER}")
if(NOT EXISTS "${COPROCESSING_TEST_DIR}/CPGrid0.png")
message(FATAL_ERROR "'${COPROCESSING_TEST_DIR}/CPGrid0.png' was not created")
endif()
if(NOT EXISTS "${COPROCESSING_TEST_DIR}/CPPressure0.png")
message(FATAL_ERROR "'${COPROCESSING_TEST_DIR}/CPPressure0.png' was not created")
endif()
execute_process(COMMAND "${COPROCESSING_IMAGE_TESTER}"
"${COPROCESSING_TEST_DIR}/CPGrid0.png" 20 -V "${COPROCESSING_DATA_DIR}/CPGrid0.png" -T "${COPROCESSING_TEST_DIR}"
RESULT_VARIABLE failed)
if(failed)
message(FATAL_ERROR "CPGrid0 image compare failed.")
endif()
execute_process(COMMAND "${COPROCESSING_IMAGE_TESTER}"
"${COPROCESSING_TEST_DIR}/CPPressure0.png" 20 -V "${COPROCESSING_DATA_DIR}/CPPressure0.png" -T "${COPROCESSING_TEST_DIR}"
RESULT_VARIABLE failed)
if(failed)
message(FATAL_ERROR "CPPressure0 image compare failed.")
endif()
endif()

View File

@ -0,0 +1,72 @@
/*=========================================================================
Program: ParaView
Module: CompareImages.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkImageData.h"
#include "vtkPNGReader.h"
#include "vtkSmartPointer.h"
#include <vtksys/SystemTools.hxx>
#include "vtkTesting.h"
// Checks to see if the file exists and that it is a png file.
// Returns 1 for a valid file and 0 for an invalid file.
int IsFileValid(const char* fileName)
{
if(vtksys::SystemTools::FileExists(fileName) == 0)
{
vtkGenericWarningMacro("Could not find file " << fileName);
return 0;
}
if(vtksys::SystemTools::GetFilenameLastExtension(fileName) != ".png")
{
vtkGenericWarningMacro("Wrong file type " << fileName);
return 0;
}
return 1;
}
int main(int argc, char* argv[])
{
if(argc != 7)
{
vtkGenericWarningMacro("Must specify files to compare.");
vtkGenericWarningMacro(
"<exe> TestImage.png <Threshold> -V BaselineImage.png -T TempDirectory");
return 1;
}
const char* baselineImage = argv[4];
const char* testImage = argv[1];
if(IsFileValid(baselineImage) == 0 || IsFileValid(testImage) == 0)
{
return 1;
}
vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();
reader->SetFileName(testImage);
reader->Update();
vtkSmartPointer<vtkTesting> testing = vtkSmartPointer<vtkTesting>::New();
for (int cc = 1; cc < argc; cc ++ )
{
testing->AddArgument(argv[cc]);
}
double threshold = atof(argv[2]);
if(!testing->RegressionTest(reader, threshold))
{
return 1;
}
return 0;
}

View File

@ -0,0 +1,64 @@
/*=========================================================================
Program: ParaView
Module: PythonScriptCoProcessingExample.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Build the grid inside of vtkCustomTestDriver. This also calls the
// python coprocessor.
#include "vtkPVCustomTestDriver.h"
#include "vtkPVConfig.h"
#ifdef PARAVIEW_USE_MPI
# define MPICH_SKIP_MPICXX
# include "vtkMPI.h"
#endif
#include <iostream>
int main(int argc, char* argv[])
{
if(argc < 2)
{
cerr << "Wrong number of arguments. Command is: <exe> <python script>\n";
return 1;
}
#ifdef PARAVIEW_USE_MPI
MPI_Init(&argc,&argv);
#endif
int errors = 0;
vtkPVCustomTestDriver* testDriver = vtkPVCustomTestDriver::New();
if(testDriver->Initialize(argv[1]))
{
testDriver->SetNumberOfTimeSteps(1);
testDriver->SetStartTime(0);
testDriver->SetEndTime(.5);
if(testDriver->Run())
{
errors++;
}
testDriver->Finalize();
}
else
{
errors++;
}
testDriver->Delete();
#ifdef PARAVIEW_USE_MPI
MPI_Finalize();
#endif
cout << "Finished run with " << errors << " errors.\n";
return errors;
}

View File

@ -0,0 +1,70 @@
# the code below is needed to import objects from paraview.simple
# plus the definition of vtkTrivialProducer into this python script.
try: paraview.simple
except: from paraview.simple import *
def DoCoProcessing(datadescription):
timestep = datadescription.GetTimeStep()
grid = datadescription.GetInputDescriptionByName("input").GetGrid()
pressure = grid.GetPointData().GetArray('Pressure')
grid.GetPointData().SetScalars(pressure)
trivialproducer = PVTrivialProducer()
obj = trivialproducer.GetClientSideObject()
obj.SetOutput(grid)
if grid.IsA("vtkImageData") == True or grid.IsA("vtkStructuredGrid") == True or grid.IsA("vtkRectilinearGrid") == True:
extent = datadescription.GetInputDescriptionByName("input").GetWholeExtent()
trivialproducer.WholeExtent= [ extent[0], extent[1], extent[2], extent[3], extent[4], extent[5] ]
# get global range of Pressure
trivialproducer.UpdatePipeline()
RenderView1 = GetRenderView()
RenderView1.ViewSize = [200, 300]
DataRepresentation1 = Show()
DataRepresentation1.Visibility = 0
Contour1 = Contour( PointMergeMethod="Uniform Binning" )
Contour1.PointMergeMethod = "Uniform Binning"
Contour1.ContourBy = ['POINTS', 'Pressure']
Contour1.Isosurfaces = [2952.0]
RenderView1.Background = [1,1,1]
RenderView1.CameraPosition = [5.0, 25.0, 347.53624862725769]
RenderView1.CameraFocalPoint = [5.0, 25.0, 307.5]
RenderView1.CameraClippingRange = [24.710886140985117, 59.424292356666555]
RenderView1.CameraParallelScale = 13.743685418725535
DataRepresentation2 = Show()
DataRepresentation2.ScaleFactor = 1.5
DataRepresentation2.EdgeColor = [0.0, 0.0, 0.50000762951094835]
fname = 'CPGrid' + str(timestep) + '.png'
WriteImage(fname)
DataRepresentation2 = Show(trivialproducer)
DataRepresentation2.LookupTable = MakeBlueToRedLT(2702, 3202)
DataRepresentation2.ColorArrayName = ('POINTS', 'Pressure')
DataRepresentation2.Representation="Surface"
DataRepresentation2 = Show(Contour1)
RenderView1 = Render()
RenderView1.Background=[1,1,1] #white
RenderView1.CameraPosition = [5.0, 25.0, 347.53624862725769]
RenderView1.CameraFocalPoint = [5.0, 25.0, 307.5]
RenderView1.CameraClippingRange = [24.710886140985117, 59.424292356666555]
RenderView1.CameraParallelScale = 13.743685418725535
fname = 'CPPressure' + str(timestep) + '.png'
WriteImage(fname)
def RequestDataDescription(datadescription):
time = datadescription.GetTime()
timestep = datadescription.GetTimeStep()
if timestep % 20 == 0:
# add in some fields
#print 'added Pressure and wanting to do coprocessing'
datadescription.GetInputDescriptionByName("input").AddPointField("Pressure")
datadescription.GetInputDescriptionByName('input').GenerateMeshOn()
return

View File

@ -0,0 +1,84 @@
try: paraview.simple
except: from paraview.simple import *
from paraview import coprocessing
import sys
# ----------------------- CoProcessor definition -----------------------
def CreateCoProcessor():
def _CreatePipeline(coprocessor, datadescription):
class Pipeline:
Wavelet1 = coprocessor.CreateProducer( datadescription, "input" )
return Pipeline()
class CoProcessor(coprocessing.CoProcessor):
def CreatePipeline(self, datadescription):
self.Pipeline = _CreatePipeline(self, datadescription)
coprocessor = CoProcessor()
freqs = {'input': [1]}
coprocessor.SetUpdateFrequencies(freqs)
return coprocessor
#--------------------------------------------------------------
# Global variables that will hold the pipeline for each timestep
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
# It will be automatically setup when coprocessor.UpdateProducers() is called the
# first time.
coprocessor = CreateCoProcessor()
#--------------------------------------------------------------
# Enable Live-Visualizaton with ParaView
coprocessor.EnableLiveVisualization(False, 1)
# ---------------------- Data Selection method ----------------------
def RequestDataDescription(datadescription):
"Callback to populate the request for current timestep"
global coprocessor
if datadescription.GetForceOutput() == True:
# We are just going to request all fields and meshes from the simulation
# code/adaptor.
for i in range(datadescription.GetNumberOfInputDescriptions()):
datadescription.GetInputDescription(i).AllFieldsOn()
datadescription.GetInputDescription(i).GenerateMeshOn()
return
# setup requests for all inputs based on the requirements of the
# pipeline.
coprocessor.LoadRequestedData(datadescription)
# ------------------------ Processing method ------------------------
def DoCoProcessing(datadescription):
"Callback to do co-processing for current timestep"
global coprocessor
timestep = datadescription.GetTimeStep()
print "Timestep:", timestep, "Time:", datadescription.GetTime()
# Update the coprocessor by providing it the newly generated simulation data.
# If the pipeline hasn't been setup yet, this will setup the pipeline.
coprocessor.UpdateProducers(datadescription)
pipeline = coprocessor.Pipeline
grid = servermanager.Fetch(pipeline.Wavelet1)
array = grid.GetPointData().GetArray("RTData")
array_range = array.GetRange()
if timestep == 0:
if array_range[0] < 37 or array_range[0] > 38 or array_range[1] < 276 or array_range[1] > 277:
print 'ERROR: bad range of ', array_range, ' for step 0'
sys.exit(1)
if timestep == 1:
if array_range[0] < 74 or array_range[0] > 76 or array_range[1] < 443 or array_range[1] > 445:
print 'ERROR: bad range of ', array_range, ' for step 1'
sys.exit(1)
if timestep == 2:
if array_range[0] < 77 or array_range[0] > 79 or array_range[1] < 357 or array_range[1] > 458:
print 'ERROR: bad range of ', array_range, ' for step 2'
sys.exit(1)
if timestep == 3:
if array_range[0] < -43 or array_range[0] > 44 or array_range[1] < 304 or array_range[1] > 305:
print 'ERROR: bad range of ', array_range, ' for step 3'
sys.exit(1)

View File

@ -0,0 +1,12 @@
# Script to make sure we can import other scripts from
# a Catalyst script
import cpprogrammablefilter
def RequestDataDescription(datadescription):
"Callback to populate the request for current timestep -- NULL for this test"
pass
def DoCoProcessing(datadescription):
"Callback to do co-processing for current timestep -- NULL for this test"
pass

View File

@ -0,0 +1,99 @@
from paraview.simple import *
from paraview import coprocessing
#--------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.
# ParaView 4.2.0-RC1-22-g9ca4e44 64 bits
# ----------------------- CoProcessor definition -----------------------
def CreateCoProcessor():
def _CreatePipeline(coprocessor, datadescription):
class Pipeline:
# state file generated using paraview version 4.2.0-RC1-22-g9ca4e44
# ----------------------------------------------------------------
# setup the data processing pipelines
# ----------------------------------------------------------------
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'XML Partitioned Unstructured Grid Reader'
# create a producer from a simulation input
outputcp_98pvtu = coprocessor.CreateProducer(datadescription, 'input')
# create a new 'Programmable Filter'
programmableFilter1 = ProgrammableFilter(Input=outputcp_98pvtu)
programmableFilter1.Script = 'pdi = self.GetInput()\nnumPts = pdi.GetNumberOfPoints()\nca = vtk.vtkFloatArray()\nca.SetName("dogs")\nca.SetNumberOfComponents(1)\nca.SetNumberOfTuples(numPts)\nfor i in range(numPts):\n ca.SetValue(i, 100)\n\nido = self.GetOutput()\nido.GetPointData().AddArray(ca)'
programmableFilter1.RequestInformationScript = ''
programmableFilter1.RequestUpdateExtentScript = ''
programmableFilter1.PythonPath = ''
# create a new 'Parallel UnstructuredGrid Writer'
#parallelUnstructuredGridWriter1 = servermanager.writers.XMLPUnstructuredGridWriter(Input=programmableFilter1)
# register the writer with coprocessor
# and provide it with information such as the filename to use,
# how frequently to write the data, etc.
#coprocessor.RegisterWriter(parallelUnstructuredGridWriter1, filename='cppf_%t.pvtu', freq=10)
return Pipeline()
class CoProcessor(coprocessing.CoProcessor):
def CreatePipeline(self, datadescription):
self.Pipeline = _CreatePipeline(self, datadescription)
coprocessor = CoProcessor()
# these are the frequencies at which the coprocessor updates.
freqs = {'input': [10]}
coprocessor.SetUpdateFrequencies(freqs)
return coprocessor
#--------------------------------------------------------------
# Global variables that will hold the pipeline for each timestep
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
# It will be automatically setup when coprocessor.UpdateProducers() is called the
# first time.
coprocessor = CreateCoProcessor()
#--------------------------------------------------------------
# Enable Live-Visualizaton with ParaView
coprocessor.EnableLiveVisualization(False, 1)
# ---------------------- Data Selection method ----------------------
def RequestDataDescription(datadescription):
"Callback to populate the request for current timestep"
global coprocessor
if datadescription.GetForceOutput() == True:
# We are just going to request all fields and meshes from the simulation
# code/adaptor.
for i in range(datadescription.GetNumberOfInputDescriptions()):
datadescription.GetInputDescription(i).AllFieldsOn()
datadescription.GetInputDescription(i).GenerateMeshOn()
return
# setup requests for all inputs based on the requirements of the
# pipeline.
coprocessor.LoadRequestedData(datadescription)
# ------------------------ Processing method ------------------------
def DoCoProcessing(datadescription):
"Callback to do co-processing for current timestep"
global coprocessor
# Update the coprocessor by providing it the newly generated simulation data.
# If the pipeline hasn't been setup yet, this will setup the pipeline.
coprocessor.UpdateProducers(datadescription)
# Write output data, if appropriate.
coprocessor.WriteData(datadescription);
# Write image capture (Last arg: rescale lookup table), if appropriate.
coprocessor.WriteImages(datadescription, rescale_lookuptable=False)
# Live Visualization, if enabled.
coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)

View File

@ -0,0 +1,20 @@
import sys
if len(sys.argv) != 2:
print "command is 'python <vtk file>'"
sys.exit(1)
from paraview.simple import *
proxy = OpenDataFile(sys.argv[1])
r = proxy.GetClientSideObject()
r.Update()
g = r.GetOutput()
if g.GetNumberOfPoints() != 441 or g.GetNumberOfCells() != 800:
print 'Output grid is incorrect. The number of points is', g.GetNumberOfPoints(), \
'but should be 441 and the number of cells is', g.GetNumberOfCells(), \
'but should be 800.'
sys.exit(1)
else:
print "All's good!!!!"

View File

@ -0,0 +1,193 @@
/*=========================================================================
Program: ParaView
Module: vtkPVCustomTestDriver.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPVCustomTestDriver.h"
#include "vtkCommunicator.h"
#include "vtkCPDataDescription.h"
#include "vtkCPInputDataDescription.h"
#include "vtkCPLinearScalarFieldFunction.h"
#include "vtkCPNodalFieldBuilder.h"
#include "vtkCPProcessor.h"
#include "vtkCPPythonScriptPipeline.h"
#include "vtkCPUniformGridBuilder.h"
#include "vtkDataObject.h"
#include "vtkImageData.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
vtkStandardNewMacro(vtkPVCustomTestDriver);
//----------------------------------------------------------------------------
vtkPVCustomTestDriver::vtkPVCustomTestDriver()
{
this->Processor = vtkCPProcessor::New();
this->Processor->Initialize();
// Specify how the field varies over space and time.
vtkCPLinearScalarFieldFunction* fieldFunction =
vtkCPLinearScalarFieldFunction::New();
fieldFunction->SetConstant(2.);
fieldFunction->SetTimeMultiplier(100);
fieldFunction->SetXMultiplier(23.);
fieldFunction->SetYMultiplier(15.);
fieldFunction->SetZMultiplier(8.);
// Specify how to construct the field over the grid.
vtkCPNodalFieldBuilder* fieldBuilder = vtkCPNodalFieldBuilder::New();
fieldBuilder->SetArrayName("Pressure");
fieldBuilder->SetTensorFieldFunction(fieldFunction);
fieldFunction->Delete();
// Set the type of grid we are building.
vtkCPUniformGridBuilder* gridBuilder = vtkCPUniformGridBuilder::New();
int dimensions[3] = {50, 50, 50};
gridBuilder->SetDimensions(dimensions);
double spacing[3] = {.2, .2, .3};
gridBuilder->SetSpacing(spacing);
double origin[3] = {0,20,300};
gridBuilder->SetOrigin(origin);
gridBuilder->SetFieldBuilder(fieldBuilder);
fieldBuilder->Delete();
this->SetGridBuilder(gridBuilder);
gridBuilder->Delete();
}
//----------------------------------------------------------------------------
vtkPVCustomTestDriver::~vtkPVCustomTestDriver()
{
if(this->Processor)
{
this->Processor->Delete();
this->Processor = 0;
}
}
//----------------------------------------------------------------------------
int vtkPVCustomTestDriver::Run()
{
vtkCPBaseGridBuilder* gridBuilder = this->GetGridBuilder();
if(gridBuilder == 0)
{
vtkErrorMacro("Need to set the grid builder.");
return 1;
}
for(unsigned long i=0;i<this->GetNumberOfTimeSteps();i++)
{
// now call the coprocessing library
vtkCPDataDescription* dataDescription = vtkCPDataDescription::New();
double time = this->GetTime(i);
dataDescription->SetTimeData(time, i);
dataDescription->AddInput("input");
if(this->Processor->RequestDataDescription(dataDescription))
{
unsigned int numberOfFields =
dataDescription->GetInputDescriptionByName("input")->GetNumberOfFields();
if(!numberOfFields)
{
cout << "No fields for coprocessing.\n";
}
int builtNewGrid = 0;
vtkDataObject* grid = gridBuilder->GetGrid(i, this->GetTime(i), builtNewGrid);
dataDescription->GetInputDescriptionByName("input")->SetGrid(grid);
// we need to get the whole extent of any structured grids
int extent[6];
if(vtkImageData* image = vtkImageData::SafeDownCast(grid))
{
image->GetExtent(extent);
}
else if(vtkRectilinearGrid* rgrid = vtkRectilinearGrid::SafeDownCast(grid))
{
rgrid->GetExtent(extent);
}
else if(vtkStructuredGrid* sgrid = vtkStructuredGrid::SafeDownCast(grid))
{
sgrid->GetExtent(extent);
}
for(int j=0;j<3;j++)
{
extent[2*j] = -extent[2*j];
}
int wholeExtent[6];
vtkMultiProcessController::GetGlobalController()->AllReduce(extent, wholeExtent, 6, vtkCommunicator::MAX_OP);
for(int j=0;j<3;j++)
{
wholeExtent[2*j] = -wholeExtent[2*j];
}
dataDescription->GetInputDescriptionByName("input")->SetWholeExtent(wholeExtent);
this->Processor->CoProcess(dataDescription);
}
dataDescription->Delete();
}
return 0;
}
//----------------------------------------------------------------------------
int vtkPVCustomTestDriver::Initialize(const char* fileName)
{
vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New();
int success = pipeline->Initialize(fileName);
this->Processor->AddPipeline(pipeline);
pipeline->Delete();
// test adding a second pipeline and then deleting it
vtkCPPythonScriptPipeline* tempPipeline = vtkCPPythonScriptPipeline::New();
this->Processor->AddPipeline(tempPipeline);
tempPipeline->Delete();
if(this->Processor->GetNumberOfPipelines() != 2)
{
vtkErrorMacro("Wrong amount of pipelines.");
success = 0;
}
else if(this->Processor->GetPipeline(0) != pipeline ||
this->Processor->GetPipeline(1) != tempPipeline)
{
vtkErrorMacro("Bad ordering of the processor's pipeline.");
success = 0;
}
this->Processor->RemovePipeline(tempPipeline);
if(this->Processor->GetNumberOfPipelines() != 1)
{
vtkErrorMacro("Wrong amount of pipelines.");
success = 0;
}
else if(this->Processor->GetPipeline(0) != pipeline)
{
vtkErrorMacro("Bad ordering of the processor's pipeline.");
success = 0;
}
return success;
}
//----------------------------------------------------------------------------
int vtkPVCustomTestDriver::Finalize()
{
this->Processor->Finalize();
return 1;
}
//----------------------------------------------------------------------------
void vtkPVCustomTestDriver::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Processor: " << this->Processor << endl;
}

View File

@ -0,0 +1,62 @@
/*=========================================================================
Program: ParaView
Module: vtkPVCustomTestDriver.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPVCustomTestDriver - A custom test driver code that uses ParaView and python.
// .SECTION Description
// A custom test driver that creates a vtkUniformGrid with a single
// scalar point field named "Pressure". It runs a python script
// using ParaView.
#ifndef vtkPVCustomTestDriver_h
#define vtkPVCustomTestDriver_h
#include "vtkCPTestDriver.h"
class vtkCPProcessor;
class VTK_EXPORT vtkPVCustomTestDriver : public vtkCPTestDriver
{
public:
static vtkPVCustomTestDriver * New();
vtkTypeMacro(vtkPVCustomTestDriver, vtkCPTestDriver);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Run the test driver with the coprocessor.
// Returns 0 if there were no errors.
virtual int Run();
// Description:
// Initialize the driver with the coprocessor. fileName is the
// name of the python script. Returns 0 on failure.
virtual int Initialize(const char* fileName);
// Description:
// Finalize the driver with the coprocessor.
virtual int Finalize();
protected:
vtkPVCustomTestDriver();
~vtkPVCustomTestDriver();
private:
vtkPVCustomTestDriver(const vtkPVCustomTestDriver&); // Not implemented
void operator=(const vtkPVCustomTestDriver&); // Not implemented
// Description:
// The coprocessor to be called by this custom test.
vtkCPProcessor* Processor;
};
#endif

View File

@ -0,0 +1,80 @@
import sys
if len(sys.argv) != 3:
print "command is 'python <python driver code> <script name> <number of time steps>'"
sys.exit(1)
import paraview
import paraview.vtk as vtk
import paraview.simple as pvsimple
import math
# initialize and read input parameters
paraview.options.batch = True
paraview.options.symmetric = True
def _refHolderMaker(obj):
def _refHolder(obj2, string):
tmp = obj
return _refHolder
def coProcess(grid, time, step, scriptname, wholeExtent):
import vtkPVCatalystPython
import os
scriptpath, scriptname = os.path.split(scriptname)
sys.path.append(scriptpath)
if scriptname.endswith(".py"):
print 'script name is ', scriptname
scriptname = scriptname[0:len(scriptname)-3]
try:
cpscript = __import__(scriptname)
except:
print sys.exc_info()
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
sys.exit(1)
return
datadescription = vtkPVCatalystPython.vtkCPDataDescription()
datadescription.SetTimeData(time, step)
datadescription.AddInput("input")
cpscript.RequestDataDescription(datadescription)
inputdescription = datadescription.GetInputDescriptionByName("input")
if inputdescription.GetIfGridIsNecessary() == False:
return
inputdescription.SetGrid(grid)
if grid.IsA("vtkImageData") == True or grid.IsA("vtkRectilinearGrid") == True \
or grid.IsA("vtkStructuredGrid") == True:
inputdescription.SetWholeExtent(wholeExtent)
cpscript.DoCoProcessing(datadescription)
try:
numsteps = int(sys.argv[2])
except ValueError:
print 'the last argument should be a number'
numsteps = 10
#imageData2 = vtk.vtkImageData()
for step in range(numsteps):
# assume simulation time starts at 0
time = step/float(numsteps)
# create the input to the coprocessing library. normally
# this will come from the adaptor
wavelet = pvsimple.Wavelet()
wholeExtent = wavelet.WholeExtent
# put in some variation in the point data that changes with time
wavelet.Maximum = 255+200*math.sin(step)
wavelet.UpdatePipeline()
imageData = pvsimple.servermanager.Fetch(wavelet)
# note that we delete wavelet now since. if not, it will
# get deleted automatically in the coprocessing script
pvsimple.Delete(wavelet)
wavelet = None
# "perform" coprocessing. results are outputted only if
# the passed in script says we should at time/step
coProcess(imageData, time, step, sys.argv[1], wholeExtent)
imageData = None

View File

@ -0,0 +1,11 @@
vtk_module(vtkPVPythonCatalyst
DEPENDS
vtkPVCatalyst
vtkPythonInterpreter
TEST_DEPENDS
vtkIOImage
vtkTestingRendering
vtkPVCatalystTestDriver
TEST_LABELS
PARAVIEW CATALYST
)

View File

@ -0,0 +1,38 @@
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCPPythonAdaptorAPI.h"
#include "vtkCPProcessor.h"
#include "vtkCPPythonScriptPipeline.h"
//----------------------------------------------------------------------------
void vtkCPPythonAdaptorAPI::CoProcessorInitialize(const char* pythonFileName)
{
if (!Superclass::CoProcessor)
{
Superclass::CoProcessor = vtkCPProcessor::New();
Superclass::CoProcessor->Initialize();
}
// needed to initialize vtkCPDataDescription.
Superclass::CoProcessorInitialize();
if(pythonFileName)
{
vtkCPPythonScriptPipeline* pipeline = vtkCPPythonScriptPipeline::New();
pipeline->Initialize(pythonFileName);
Superclass::CoProcessor->AddPipeline(pipeline);
pipeline->FastDelete();
}
}

View File

@ -0,0 +1,46 @@
/*=========================================================================
Program: ParaView
Module: vtkCPPythonAdaptorAPI.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef vtkCPPythonAdaptorAPI_h
#define vtkCPPythonAdaptorAPI_h
#include "vtkCPAdaptorAPI.h"
#include "vtkPVPythonCatalystModule.h" // For windows import/export of shared libraries
/// Similar to vtkCPAdaptorAPI provides the implementation for API exposed to
/// typical adaptor, such as C, Fortran, except that is adds the ability to
/// initialize the coprocessor with Python capabilities.
class VTKPVPYTHONCATALYST_EXPORT vtkCPPythonAdaptorAPI : public vtkCPAdaptorAPI
{
public:
vtkTypeMacro(vtkCPPythonAdaptorAPI, vtkCPAdaptorAPI);
/// Call at the start of the simulation. Users can still call
/// CoProcessorInitialize() without arguments, in which case Python
/// interpretor will not be initialized and hence unavailable.
static void CoProcessorInitialize(const char* pythonFileName);
//BTX
protected:
vtkCPPythonAdaptorAPI();
~vtkCPPythonAdaptorAPI();
private:
vtkCPPythonAdaptorAPI(const vtkCPPythonAdaptorAPI&); // Not implemented
void operator=(const vtkCPPythonAdaptorAPI&); // Not implemented
//ETX
};
#endif
// VTK-HeaderTest-Exclude: vtkCPPythonAdaptorAPI.h

View File

@ -0,0 +1,27 @@
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile$
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Simply provided for backwards compatibility. Use vtkCPProcessor instead.
#ifndef vtkCPPythonProcessor_h
#define vtkCPPythonProcessor_h
#warning Please use vtkCPProcessor directly. vtkCPPythonProcessor is \
no longer available/needed.
#include "vtkCPProcessor.h"
#define vtkCPPythonProcessor vtkCPProcessor
#endif
// VTK-HeaderTest-Exclude: vtkCPPythonProcessor.h

View File

@ -0,0 +1,308 @@
/*=========================================================================
Program: ParaView
Module: vtkCPPythonScriptPipeline.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCPPythonScriptPipeline.h"
#include "vtkCPDataDescription.h"
#include "vtkDataObject.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkPVConfig.h"
#include "vtkPVPythonOptions.h"
#include "vtkPythonInterpreter.h"
#include "vtkSMObject.h"
#include "vtkSMProxyManager.h"
#include <string>
#include <vtksys/SystemTools.hxx>
#include <sstream>
extern "C" {
void vtkPVInitializePythonModules();
}
namespace
{
//----------------------------------------------------------------------------
void InitializePython()
{
static bool initialized = false;
if (initialized)
{
return;
}
initialized = true;
// register callback to initialize modules statically. The callback is
// empty when BUILD_SHARED_LIBS is ON.
vtkPVInitializePythonModules();
vtkPythonInterpreter::Initialize();
std::ostringstream loadPythonModules;
loadPythonModules
<< "import sys\n"
<< "import paraview\n"
<< "f1 = paraview.print_error\n"
<< "f2 = paraview.print_debug_info\n"
<< "def print_dummy(text):\n"
<< " pass\n"
<< "paraview.print_error = print_dummy\n"
<< "paraview.print_debug_info = print_dummy\n"
<< "paraview.print_error = f1\n"
<< "paraview.print_debug_info = f2\n"
<< "import vtkPVCatalystPython\n";
vtkPythonInterpreter::RunSimpleString(loadPythonModules.str().c_str());
}
//----------------------------------------------------------------------------
// for things like programmable filters that have a '\n' in their strings,
// we need to fix them to have \\n so that everything works smoothly
void fixEOL(std::string& str)
{
const std::string from = "\\n";
const std::string to = "\\\\n";
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
return;
}
}
vtkStandardNewMacro(vtkCPPythonScriptPipeline);
//----------------------------------------------------------------------------
vtkCPPythonScriptPipeline::vtkCPPythonScriptPipeline()
{
this->PythonScriptName = 0;
}
//----------------------------------------------------------------------------
vtkCPPythonScriptPipeline::~vtkCPPythonScriptPipeline()
{
this->SetPythonScriptName(0);
}
//----------------------------------------------------------------------------
int vtkCPPythonScriptPipeline::Initialize(const char* fileName)
{
// only process 0 checks if the file exists and broadcasts that information
// to the other processes
int fileExists = 0;
vtkMultiProcessController* controller =
vtkMultiProcessController::GetGlobalController();
if(controller->GetLocalProcessId()==0)
{
fileExists = vtksys::SystemTools::FileExists(fileName, true);
}
controller->Broadcast(&fileExists, 1, 0);
if(fileExists == 0)
{
vtkErrorMacro("Could not find file " << fileName);
return 0;
}
InitializePython();
// for now do not check on filename extension:
//vtksys::SystemTools::GetFilenameLastExtension(FileName) == ".py" == 0)
std::string fileNamePath = vtksys::SystemTools::GetFilenamePath(fileName);
std::string fileNameName = vtksys::SystemTools::GetFilenameWithoutExtension(
vtksys::SystemTools::GetFilenameName(fileName));
// need to save the script name as it is used as the name of the module
this->SetPythonScriptName(fileNameName.c_str());
// only process 0 reads the actual script and then broadcasts it out
char* scriptText = NULL;
// we need to add the script path to PYTHONPATH
char* scriptPath = NULL;
int rank = controller->GetLocalProcessId();
int scriptSizes[2] = {0, 0};
if(rank == 0)
{
std::string line;
std::ifstream myfile (fileName);
std::string desiredString;
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
fixEOL(line);
desiredString.append(line).append("\n");
}
myfile.close();
}
if(fileNamePath.empty())
{
fileNamePath = ".";
}
scriptSizes[0] = static_cast<int>(fileNamePath.size()+1);
scriptPath = new char[scriptSizes[0]];
memcpy(scriptPath, fileNamePath.c_str(), sizeof(char)*scriptSizes[0]);
scriptSizes[1] = static_cast<int>(desiredString.size()+1);
scriptText = new char[scriptSizes[1]];
memcpy(scriptText, desiredString.c_str(), sizeof(char)*scriptSizes[1]);
}
controller->Broadcast(scriptSizes, 2, 0);
if (rank != 0)
{
scriptPath = new char[scriptSizes[0]];
scriptText = new char[scriptSizes[1]];
}
controller->Broadcast(scriptPath, scriptSizes[0], 0);
controller->Broadcast(scriptText, scriptSizes[1], 0);
vtkPythonInterpreter::PrependPythonPath(scriptPath);
// The code below creates a module from the scriptText string.
// This requires the manual creation of a module object like this:
//
// import types
// _foo = types.ModuleType('foo')
// _foo.__file__ = 'foo.pyc'
// import sys
// sys.module['foo'] = _foo
// _source= scriptText
// _code = compile(_source, 'foo.py', 'exec')
// exec _code in _foo.__dict__
// del _source
// del _code
// import foo
std::ostringstream loadPythonModules;
loadPythonModules << "import types" << std::endl;
loadPythonModules << "_" << fileNameName << " = types.ModuleType('" << fileNameName << "')" << std::endl;
loadPythonModules << "_" << fileNameName << ".__file__ = '" << fileNameName << ".pyc'" << std::endl;
loadPythonModules << "import sys" << std::endl;
loadPythonModules << "sys.modules['" << fileNameName << "'] = _" << fileNameName << std::endl;
loadPythonModules << "_source = \"\"\"" << std::endl;
loadPythonModules << scriptText;
loadPythonModules << "\"\"\"" << std::endl;
loadPythonModules << "_code = compile(_source, \"" << fileNameName << ".py\", \"exec\")" << std::endl;
loadPythonModules << "exec _code in _" << fileNameName << ".__dict__" << std::endl;
loadPythonModules << "del _source" << std::endl;
loadPythonModules << "del _code" << std::endl;
loadPythonModules << "import " << fileNameName << std::endl;
delete[] scriptPath;
delete[] scriptText;
vtkPythonInterpreter::RunSimpleString(loadPythonModules.str().c_str());
return 1;
}
//----------------------------------------------------------------------------
int vtkCPPythonScriptPipeline::RequestDataDescription(
vtkCPDataDescription* dataDescription)
{
if(!dataDescription)
{
vtkWarningMacro("dataDescription is NULL.");
return 0;
}
InitializePython();
// check the script to see if it should be run...
vtkStdString dataDescriptionString = this->GetPythonAddress(dataDescription);
std::ostringstream pythonInput;
pythonInput << "dataDescription = vtkPVCatalystPython.vtkCPDataDescription('"
<< dataDescriptionString << "')\n"
<< this->PythonScriptName << ".RequestDataDescription(dataDescription)\n";
vtkPythonInterpreter::RunSimpleString(pythonInput.str().c_str());
return dataDescription->GetIfAnyGridNecessary()? 1: 0;
}
//----------------------------------------------------------------------------
int vtkCPPythonScriptPipeline::CoProcess(
vtkCPDataDescription* dataDescription)
{
if(!dataDescription)
{
vtkWarningMacro("DataDescription is NULL.");
return 0;
}
InitializePython();
vtkStdString dataDescriptionString = this->GetPythonAddress(dataDescription);
std::ostringstream pythonInput;
pythonInput
<< "dataDescription = vtkPVCatalystPython.vtkCPDataDescription('"
<< dataDescriptionString << "')\n"
<< this->PythonScriptName << ".DoCoProcessing(dataDescription)\n";
vtkPythonInterpreter::RunSimpleString(pythonInput.str().c_str());
return 1;
}
//----------------------------------------------------------------------------
int vtkCPPythonScriptPipeline::Finalize()
{
InitializePython();
std::ostringstream pythonInput;
pythonInput
<< "if hasattr(" << this->PythonScriptName << ", 'Finalize'):\n"
<< " " << this->PythonScriptName << ".Finalize()\n";
vtkPythonInterpreter::RunSimpleString(pythonInput.str().c_str());
return 1;
}
//----------------------------------------------------------------------------
vtkStdString vtkCPPythonScriptPipeline::GetPythonAddress(void* pointer)
{
char addressOfPointer[1024];
#ifdef COPROCESSOR_WIN32_BUILD
sprintf_s(addressOfPointer, "%p", pointer);
#else
sprintf(addressOfPointer, "%p", pointer);
#endif
char *aplus = addressOfPointer;
if ((addressOfPointer[0] == '0') &&
((addressOfPointer[1] == 'x') || addressOfPointer[1] == 'X'))
{
aplus += 2; //skip over "0x"
}
vtkStdString value = aplus;
return value;
}
//----------------------------------------------------------------------------
void vtkCPPythonScriptPipeline::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "PythonScriptName: " << this->PythonScriptName << "\n";
}

View File

@ -0,0 +1,76 @@
/*=========================================================================
Program: ParaView
Module: vtkCPPythonScriptPipeline.h
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef vtkCPPythonScriptPipeline_h
#define vtkCPPythonScriptPipeline_h
#include "vtkCPPipeline.h"
#include "vtkStdString.h" // for the string
#include "vtkPVPythonCatalystModule.h" // For windows import/export of shared libraries
class vtkCPDataDescription;
/// @ingroup CoProcessing
/// Class that creates a coprocessing pipeline starting from a coprocessing
/// script. This class only does operations with respect to the script
/// and uses the name of the script as the module to hide its definitions
/// from other python modules.
class VTKPVPYTHONCATALYST_EXPORT vtkCPPythonScriptPipeline : public vtkCPPipeline
{
public:
static vtkCPPythonScriptPipeline* New();
vtkTypeMacro(vtkCPPythonScriptPipeline,vtkCPPipeline);
void PrintSelf(ostream& os, vtkIndent indent);
/// Initialize this pipeline from given the file name of a
/// python script. Returns 1 for success and 0 for failure.
int Initialize(const char* fileName);
/// Configuration Step:
/// The coprocessor first determines if any coprocessing needs to be done
/// at this TimeStep/Time combination returning 1 if it does and 0
/// otherwise. If coprocessing does need to be performed this time step
/// it fills in the FieldNames array that the coprocessor requires
/// in order to fulfill all the coprocessing requests for this
/// TimeStep/Time combination.
virtual int RequestDataDescription(vtkCPDataDescription* dataDescription);
/// Execute the pipeline. Returns 1 for success and 0 for failure.
virtual int CoProcess(vtkCPDataDescription* dataDescription);
/// Finalize the pipeline before deleting it. A default no-op implementation
/// is given. Returns 1 for success and 0 for failure.
virtual int Finalize();
protected:
vtkCPPythonScriptPipeline();
virtual ~vtkCPPythonScriptPipeline();
/// Return the address of Pointer for the python script.
vtkStdString GetPythonAddress(void* pointer);
/// Set/get macro functinos for setting PythonScriptName.
vtkSetStringMacro(PythonScriptName);
vtkGetStringMacro(PythonScriptName);
private:
vtkCPPythonScriptPipeline(const vtkCPPythonScriptPipeline&); // Not implemented
void operator=(const vtkCPPythonScriptPipeline&); // Not implemented
/// The name of the python script (without the path or extension)
/// that is used as the namespace of the functions of the script.
char* PythonScriptName;
};
#endif