Commit 28db59b2 authored by Sebastien Barre's avatar Sebastien Barre
Browse files

Example on how to build modules outside the VTK 4.0 tree

parent e69a5e1a
#
# Set the project name.
#
PROJECT (VTKMY)
#
# Assume everything is set up correctly for build.
#
# If some requirements are not met, set it to 0.
# In that case, the build won't be done.
#
SET (VTKMY_CAN_BUILD 1)
#
# Load CMake commands that you probably should not modify.
#
INCLUDE (${VTKMY_SOURCE_DIR}/vtkMy.cmake)
#
# If everything is OK, then go into the sub directories and build.
#
IF (VTKMY_CAN_BUILD)
#
# Here is where you can list the sub-directories holding your local
# classes. Sorting classes by 'package' type like VTK does (Common,
# Rendering, Filtering, Imaging, IO, etc.) is a good thing and prevents
# numerous dependencies problems.
#
SUBDIRS (
Common
Imaging
Unsorted
)
#
# Build examples too ?
#
OPTION(BUILD_EXAMPLES "Build examples." OFF)
IF (BUILD_EXAMPLES)
SUBDIRS(Examples)
ENDIF (BUILD_EXAMPLES)
ENDIF (VTKMY_CAN_BUILD)
#
# Source files
#
# Here is where you can add the name of your local common classes.
#
SOURCE_FILES (Common_SRCS
vtkBar
)
# --------------------------------------------------------------------------
# You probably do not need to modify anything below this line
#
# Include path(s)
#
INCLUDE_DIRECTORIES(${VTKMY_BINARY_DIR}/Common)
INCLUDE_DIRECTORIES(${VTKMY_SOURCE_DIR}/Common)
#
# Create the vtkmyCommon C++ library
#
ADD_LIBRARY (vtkmyCommon Common_SRCS)
#
# Create the vtkmyCommon Tcl library
#
IF (VTKMY_WRAP_TCL)
VTK_WRAP_TCL (vtkmyCommonTCL CommonTCL_SRCS Common_SRCS)
ADD_LIBRARY (vtkmyCommonTCL SHARED CommonTCL_SRCS)
TARGET_LINK_LIBRARIES (vtkmyCommonTCL
vtkCommonTCL
${TCL_LIBRARY})
ENDIF (VTKMY_WRAP_TCL)
#
# Create the vtkmyCommon Python library
#
IF (VTKMY_WRAP_PYTHON)
VTK_WRAP_PYTHON (vtkmyCommonPython CommonPython_SRCS Common_SRCS)
IF (APPLE)
ADD_LIBRARY (vtkmyCommonPython MODULE CommonPython_SRCS)
ELSE (APPLE)
ADD_LIBRARY (vtkmyCommonPython SHARED CommonPython_SRCS)
TARGET_LINK_LIBRARIES (vtkmyCommonPython
vtkCommonPython)
ENDIF (APPLE)
IF(WIN32)
TARGET_LINK_LIBRARIES (vtkmyCommonPython
vtkCommonPython
debug ${PYTHON_DEBUG_LIBRARY}
optimized ${PYTHON_LIBRARY})
ELSE(WIN32)
TARGET_LINK_LIBRARIES (vtkmyCommonPython
vtkCommonPython
${PYTHON_LIBRARY})
ENDIF(WIN32)
ENDIF (VTKMY_WRAP_PYTHON)
#
# Create the vtkmyCommon Java library
#
IF (VTKMY_WRAP_JAVA)
VTK_WRAP_TCL (vtkmyCommonJava CommonJava_SRCS Common_SRCS)
ADD_LIBRARY (vtkmyCommonJava SHARED CommonJava_SRCS)
TARGET_LINK_LIBRARIES (vtkmyCommonJava
vtkCommonJava)
ENDIF (VTKMY_WRAP_JAVA)
#
# Link to VTK and local
#
LINK_LIBRARIES (
vtkmyCommon
vtkCommon
)
#
# Common configuration settings
#
# Do not worry about this one.
#
CONFIGURE_FILE(
${VTKMY_SOURCE_DIR}/Common/vtkmyConfigure.h.in
${VTKMY_BINARY_DIR}/Common/vtkmyConfigure.h
)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBar.cxx
Language: C++
Date: $Date$
Version: $Revision$
=========================================================================*/
#include "vtkBar.h"
#include "vtkObjectFactory.h"
//----------------------------------------------------------------------------
vtkBar* vtkBar::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkBar");
if(ret)
{
return (vtkBar*)ret;
}
// If the factory was unable to create the object, then create it here.
return new vtkBar;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBar.h
Language: C++
Date: $Date$
Version: $Revision$
=========================================================================*/
// .NAME vtkBar - Bar class for vtk
// .SECTION Description
// None.
#ifndef __vtkBar_h
#define __vtkBar_h
#include "vtkObject.h"
#include "vtkmyCommonWin32Header.h"
class VTK_MY_COMMON_EXPORT vtkBar : public vtkObject
{
public:
static vtkBar *New();
vtkTypeMacro(vtkBar,vtkObject);
protected:
vtkBar() {};
~vtkBar() {};
private:
vtkBar(const vtkBar&); // Not implemented.
void operator=(const vtkBar&); // Not implemented.
};
#endif
// .NAME vtkmyCommonWin32Header - manage Windows system differences
// .SECTION Description
// The vtkmyCommonWin32Header captures some system differences between Unix
// and Windows operating systems.
#ifndef __vtkmyCommonWin32Header_h
#define __vtkmyCommonWin32Header_h
#include <vtkmyConfigure.h>
#if defined(WIN32) && !defined(VTK_MY_STATIC)
#if defined(vtkmyCommon_EXPORTS)
#define VTK_MY_COMMON_EXPORT __declspec( dllexport )
#else
#define VTK_MY_COMMON_EXPORT __declspec( dllimport )
#endif
#else
#define VTK_MY_COMMON_EXPORT
#endif
#endif
/*
* Here is where system computed values get stored.
* These values should only change when the target compile platform changes.
*/
#if defined(WIN32) && !defined(VTKMY_STATIC)
#pragma warning ( disable : 4275 )
#endif
#cmakedefine CMAKE_WORDS_BIGENDIAN
#ifdef CMAKE_WORDS_BIGENDIAN
#define WORDS_BIGENDIAN
#else
#define WORDS_LITTLEENDIAN
#endif
#cmakedefine BUILD_SHARED_LIBS
#ifndef BUILD_SHARED_LIBS
#define VTK_MY_STATIC
#endif
SUBDIRS(
Ex1
)
#
# Include path(s)
#
INCLUDE_DIRECTORIES(${VTKMY_BINARY_DIR}/Common)
INCLUDE_DIRECTORIES(${VTKMY_SOURCE_DIR}/Common)
INCLUDE_DIRECTORIES (${VTKMY_SOURCE_DIR}/Imaging)
INCLUDE_DIRECTORIES (${VTKMY_SOURCE_DIR}/Unsorted)
#
# Link to VTK and local
#
LINK_LIBRARIES (
vtkmyUnsorted
vtkIO
vtkGraphics
vtkmyImaging
vtkImaging
vtkFiltering
vtkmyCommon
vtkCommon
)
IF (VTK_USE_HYBRID)
LINK_LIBRARIES (vtkHybrid)
ENDIF (VTK_USE_HYBRID)
IF (VTK_USE_PARALLEL)
LINK_LIBRARIES (vtkParallel)
ENDIF (VTK_USE_PARALLEL)
IF (VTK_USE_PATENTED)
LINK_LIBRARIES (vtkPatented)
ENDIF (VTK_USE_PATENTED)
IF (VTK_USE_RENDERING)
LINK_LIBRARIES (vtkRendering)
ENDIF (VTK_USE_RENDERING)
#
# Add the executable
#
ADD_EXECUTABLE(vtkmyEx1 vtkmyEx1)
#include "vtkBar.h"
#include "vtkBar2.h"
#include "vtkImageFoo.h"
int main( int argc, char *argv[] )
{
cout << "Create vtkBar object and print it." << endl;
vtkBar *bar = vtkBar::New();
bar->Print(cout);
bar->Delete();
cout << "Create vtkBar2 object and print it." << endl;
vtkBar2 *bar2 = vtkBar2::New();
bar2->Print(cout);
bar2->Delete();
cout << "Create vtkImageFoo object and print it." << endl;
vtkImageFoo *imagefoo = vtkImageFoo::New();
imagefoo->Print(cout);
imagefoo->Delete();
cout << "Looks good ?" << endl;
return 0;
}
# Do not forget to add the path to the Wrapping/Tcl directory to your
# TCLLIBPATH environment variable. Use forward slash / instead of \.
package require vtkmy
puts "Create vtkBar object and print it."
vtkBar bar
puts [bar Print]
puts "Create vtkBar2 object and print it."
vtkBar2 bar2
puts [bar2 Print]
puts "Create vtkImageFoo object and print it."
vtkImageFoo imagefoo
puts [imagefoo Print]
puts "Looks good ?"
#
# Source files
#
# Here is where you can add the name of your local imaging classes.
#
SOURCE_FILES (Imaging_SRCS
vtkImageFoo
)
# --------------------------------------------------------------------------
# You probably do not need to modify anything below this line
#
# Include path(s)
#
INCLUDE_DIRECTORIES(${VTKMY_BINARY_DIR}/Common)
INCLUDE_DIRECTORIES(${VTKMY_SOURCE_DIR}/Common)
INCLUDE_DIRECTORIES (${VTKMY_SOURCE_DIR}/Imaging)
#
# Create the vtkmyImaging C++ library
#
ADD_LIBRARY (vtkmyImaging Imaging_SRCS)
#
# Create the vtkmyImaging Tcl library
#
IF (VTKMY_WRAP_TCL)
VTK_WRAP_TCL (vtkmyImagingTCL ImagingTCL_SRCS Imaging_SRCS)
ADD_LIBRARY (vtkmyImagingTCL SHARED ImagingTCL_SRCS)
TARGET_LINK_LIBRARIES (vtkmyImagingTCL
vtkImagingTCL
vtkFilteringTCL
vtkmyCommonTCL
vtkCommonTCL
${TCL_LIBRARY})
ENDIF (VTKMY_WRAP_TCL)
#
# Create the vtkmyImaging Python library
#
IF (VTKMY_WRAP_PYTHON)
VTK_WRAP_PYTHON (vtkmyImagingPython ImagingPython_SRCS Imaging_SRCS)
IF (APPLE)
ADD_LIBRARY (vtkmyImagingPython MODULE ImagingPython_SRCS)
ELSE (APPLE)
ADD_LIBRARY (vtkmyImagingPython SHARED ImagingPython_SRCS)
TARGET_LINK_LIBRARIES (vtkmyImagingPython
vtkImagingPython
vtkFilteringPython
vtkmyCommonPython
vtkCommonPython)
ENDIF (APPLE)
IF(WIN32)
TARGET_LINK_LIBRARIES (vtkmyImagingPython
vtkImagingPython
vtkFilteringPython
vtkmyCommonPython
vtkCommonPython
debug ${PYTHON_DEBUG_LIBRARY}
optimized ${PYTHON_LIBRARY})
ELSE(WIN32)
TARGET_LINK_LIBRARIES (vtkmyImagingPython
vtkImagingPython
vtkFilteringPython
vtkmyCommonPython
vtkCommonPython
${PYTHON_LIBRARY})
ENDIF(WIN32)
ENDIF (VTKMY_WRAP_PYTHON)
#
# Create the vtkmyImaging Java library
#
IF (VTKMY_WRAP_JAVA)
VTK_WRAP_TCL (vtkmyImagingJava ImagingJava_SRCS Imaging_SRCS)
ADD_LIBRARY (vtkmyImagingJava SHARED ImagingJava_SRCS)
TARGET_LINK_LIBRARIES (vtkmyImagingJava
vtkImagingJava
vtkFilteringJava
vtkmyCommonJava
vtkCommonJava)
ENDIF (VTKMY_WRAP_JAVA)
#
# Link to VTK and local
#
LINK_LIBRARIES (
vtkmyImaging
vtkImaging
vtkFiltering
vtkmyCommon
vtkCommon
)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageFoo.cxx
Language: C++
Date: $Date$
Version: $Revision$
=========================================================================*/
#include "vtkBar.h"
#include "vtkImageFoo.h"
#include "vtkObjectFactory.h"
//----------------------------------------------------------------------------
vtkImageFoo* vtkImageFoo::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkImageFoo");
if(ret)
{
return (vtkImageFoo*)ret;
}
// If the factory was unable to create the object, then create it here.
return new vtkImageFoo;
}
//----------------------------------------------------------------------------
vtkImageFoo::vtkImageFoo()
{
this->Foo = 0.0;
this->OutputScalarType = -1;
this->Bar = vtkBar::New();
}
//----------------------------------------------------------------------------
vtkImageFoo::~vtkImageFoo()
{
if (this->Bar)
{
this->Bar->Delete();
this->Bar = NULL;
}
}
//----------------------------------------------------------------------------
void vtkImageFoo::ExecuteInformation(vtkImageData *inData,
vtkImageData *outData)
{
this->vtkImageToImageFilter::ExecuteInformation(inData, outData);
if (this->OutputScalarType != -1)
{
outData->SetScalarType(this->OutputScalarType);
}
}
//----------------------------------------------------------------------------
// This templated function executes the filter for any type of data.
template <class IT, class OT>
static void vtkImageFooExecute(vtkImageFoo *self,
vtkImageData *inData, IT *inPtr,
vtkImageData *outData, OT *outPtr,
int outExt[6], int id)
{
float foo = self->GetFoo();
int idxR, idxY, idxZ;
int maxY, maxZ;
int inIncX, inIncY, inIncZ;
int outIncX, outIncY, outIncZ;
int rowLength;
unsigned long count = 0;
unsigned long target;
// find the region to loop over
rowLength = (outExt[1] - outExt[0]+1)*inData->GetNumberOfScalarComponents();
maxY = outExt[3] - outExt[2];
maxZ = outExt[5] - outExt[4];
target = (unsigned long)((maxZ+1)*(maxY+1)/50.0);
target++;
// Get increments to march through data
inData->GetContinuousIncrements(outExt, inIncX, inIncY, inIncZ);
outData->GetContinuousIncrements(outExt, outIncX, outIncY, outIncZ);
// Loop through ouput pixels
for (idxZ = 0; idxZ <= maxZ; idxZ++)
{
for (idxY = 0; !self->AbortExecute && idxY <= maxY; idxY++)
{
for (idxR = 0; idxR < rowLength; idxR++)
{
// Pixel operation. Add foo. Dumber would be impossible.
*outPtr = (OT)((float)(*inPtr) + foo);
outPtr++;
inPtr++;
}
outPtr += outIncY;
inPtr += inIncY;
}
outPtr += outIncZ;
inPtr += inIncZ;
}
}
//----------------------------------------------------------------------------
template <class T>
static void vtkImageFooExecute1(vtkImageFoo *self,
vtkImageData *inData, T *inPtr,
vtkImageData *outData,
int outExt[6], int id)
{
void *outPtr = outData->GetScalarPointerForExtent(outExt);
switch (outData->GetScalarType())
{
vtkTemplateMacro7(vtkImageFooExecute, self, inData, inPtr,
outData, (VTK_TT *)(outPtr),outExt, id);
default:
vtkGenericWarningMacro("Execute: Unknown input ScalarType");
return;
}
}
//----------------------------------------------------------------------------
// This method is passed a input and output data, and executes the filter
// algorithm to fill the output from the input.
// It just executes a switch statement to call the correct function for
// the datas data types.
void vtkImageFoo::ThreadedExecute(vtkImageData *inData,
vtkImageData *outData,
int outExt[6], int id)
{
void *inPtr = inData->GetScalarPointerForExtent(outExt);
switch (inData->GetScalarType())
{
vtkTemplateMacro6(vtkImageFooExecute1, this,
inData, (VTK_TT *)(inPtr), outData, outExt, id);
default:
vtkErrorMacro(<< "Execute: Unknown ScalarType");