Skip to content
Snippets Groups Projects
Commit a1b94644 authored by Bill Lorensen's avatar Bill Lorensen
Browse files

ENH: Transitioning VTK/Examples to VTKExamples

Former-commit-id: 136bb64e
parent 92b0ebe7
No related branches found
No related tags found
No related merge requests found
Showing
with 927 additions and 3 deletions
......@@ -521,6 +521,8 @@ This section includes vtkImageData vtkStructuredGrid and vtkRectilinearGrid.
| Example Name | Classes Demonstrated | Description | Image |
|--------------|----------------------|-------------|-------|
[GenerateCubesFromLabels](/Cxx/Medical/GenerateCubesFromLabels) | vtkMetaImageReader vtkMaskFields |Create cubes from labeled volume data.
[GenerateModelsFromLabels](/Cxx/Medical/GenerateModelsFromLabels) | vtkDiscreteMarchingCubes vtkWindowedSincPolyDataFilter | Create models from labeled volume data (vtkDiscreteMarchingCubes).
[MedicalDemo1](/Cxx/Medical/MedicalDemo1) | vtkMarchingCubes |Create a skin surface from volume data
[MedicalDemo2](/Cxx/Medical/MedicalDemo2) | vtkMarchingCubes |Create a skin and bone surface from volume data
[MedicalDemo3](/Cxx/Medical/MedicalDemo3) | vtkMarchingCubes |Create skin, bone and slices from volume data
......@@ -536,8 +538,6 @@ This section includes vtkImageData vtkStructuredGrid and vtkRectilinearGrid.
[ExtractSurfaceDemo](/Cxx/Points/ExtractSurfaceDemo) | vtkExtractSurface vtkPCANormalEstimation vtkSignedDistance |Create a surface from Unorganized Points using Point filters (DEMO).
[ExtractSurface](/Cxx/Points/ExtractSurface) | vtkExtractSurface vtkPCANormalEstimation vtkSignedDistance |Create a surface from Unorganized Points using Point filters.
[GaussianSplat](/Cxx/Filtering/GaussianSplat) | vtkGaussianSplatter |Create a surface from Unorganized Points (Gaussian Splat).
[GenerateCubesFromLabels](/Cxx/Medical/GenerateCubesFromLabels) | vtkMetaImageReader vtkMaskFields |Create cubes from labeled volume data.
[GenerateModelsFromLabels](/Cxx/Medical/GenerateModelsFromLabels) | vtkDiscreteMarchingCubes |Create models from labeled volume data (Discrete MarchingCubes).
[SurfaceFromUnorganizedPointsWithPostProc](/Cxx/Filtering/SurfaceFromUnorganizedPointsWithPostProc) | vtkSurfaceReconstructionFilter |Create a surface from Unorganized Points (with post processing).
[SurfaceFromUnorganizedPoints](/Cxx/Filtering/SurfaceFromUnorganizedPoints) | vtkSurfaceReconstructionFilter |Create a surface from Unorganized Points.
[TriangulateTerrainMap](/Cxx/Filtering/TriangulateTerrainMap) | vtkDelaunay2D | Generate heights (z values) on a 10x10 grid (a terrain map) and then triangulate the points to form a surface.
......@@ -780,6 +780,7 @@ This section includes vtkImageData vtkStructuredGrid and vtkRectilinearGrid.
[AmbientSpheres](/Cxx/Rendering/AmbientSpheres)| vtkProperty |Demonstrates the effect of ambient lighting on spheres.
[CylinderRenderingProperties](/Cxx/Rendering/CylinderRenderingProperties)| vtkProperty |Change the properties of a cylinder.
[DiffuseSpheres](/Cxx/Rendering/DiffuseSpheres)| vtkProperty |Demonstrates the effect of diffuse lighting on spheres.
[Rainbow](/Cxx/Rendering/Rainbow)| vtkLookupTable | Use and manipulation of vtkLookupTables.
[SpecularSpheres](/Cxx/Rendering/SpecularSpheres)| vtkProperty |Demonstrates the effect of specular lighting on spheres.
......@@ -920,10 +921,11 @@ See [this tutorial](http://www.vtk.org/Wiki/VTK/Tutorials/3DDataTypes) for a bri
| Example Name | Classes Demonstrated | Description | Image |
|--------------|----------------------|-------------|-------|
[FixedPointVolumeRayCastMapperCT](/Cxx/VolumeRendering/FixedPointVolumeRayCastMapperCT)| vtkFixedPointVolumeRayCastMapper vtkColorTransferFunction vtkDICOMImageReader vtkMetaImageReader | Volume render DICOM or Meta volumes with various vtkColorTransferFunction's.
[HAVS](/Cxx/VolumeRendering/HAVSVolumeMapper)| vtkHAVSVolumeMapper |
[IntermixedUnstructuredGrid](/Cxx/VolumeRendering/IntermixedUnstructuredGrid)| vtkUnstructuredGridVolumeRayCastMapper vtkSLCReader |mix of poly data and unstructured grid volume mapper.
[MinIntensityRendering](/Cxx/VolumeRendering/MinIntensityRendering)| vtkFixedPointVolumeRayCastMapper |Min intensity rendering.
[SmartVolumeMapper](/Cxx/VolumeRendering/SmartVolumeMapper)| vtkSmartVolumeMapper |Smart volume mapper.
[IntermixedUnstructuredGrid](/Cxx/VolumeRendering/IntermixedUnstructuredGrid)| vtkUnstructuredGridVolumeRayCastMapper vtkSLCReader |mix of poly data and unstructured grid volume mapper.
## User Interaction
......
// .NAME Generate2DAMRDataSetWithPulse.cxx -- Generates sample 2-D AMR dataset
//
// .SECTION Description
// This utility code generates a simple 2D AMR dataset with a gaussian
// pulse at the center. The resulting AMR dataset is written using the
// vtkXMLHierarchicalBoxDataSetWriter.
#include <iostream>
#include <cmath>
#include <sstream>
#include <vtkSmartPointer.h>
#include <vtkAMRUtilities.h>
#include <vtkCell.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDoubleArray.h>
#include <vtkOverlappingAMR.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkUniformGrid.h>
#include <vtkAMRBox.h>
#include <vtkCompositeDataWriter.h>
#include <vtkHierarchicalBoxDataSet.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkXMLHierarchicalBoxDataReader.h>
#include <vtkXMLImageDataWriter.h>
#include <vtkXMLMultiBlockDataWriter.h>
namespace AMRCommon
{
void WriteUniformGrid( vtkUniformGrid *g, const std::string &prefix );
void WriteAMRData( vtkOverlappingAMR *amrData, const std::string &prefix );
vtkHierarchicalBoxDataSet* ReadAMRData( const std::string &file );
void WriteMultiBlockData( vtkMultiBlockDataSet *mbds, const std::string &prefix );
vtkUniformGrid* GetGrid( double* origin,double* h,int* ndim );
void ComputeCellCenter( vtkUniformGrid *grid, const int cellIdx, double c[3] );
}
namespace
{
struct PulseAttributes {
double origin[3]; // xyz for the center of the pulse
double width[3]; // the width of the pulse
double amplitude; // the amplitude of the pulse
} Pulse;
//
// Function prototype declarations
//
// Description:
// Sets the pulse attributes
void SetPulse();
// Description:
// Constructs the vtkHierarchicalBoxDataSet.
vtkOverlappingAMR* GetAMRDataSet();
// Description:
// Attaches the pulse to the given grid.
void AttachPulseToGrid( vtkUniformGrid *grid );
}
//
// Program main
//
int main( int, char *[] )
{
// STEP 0: Initialize gaussian pulse parameters
SetPulse();
// STEP 1: Get the AMR dataset
vtkOverlappingAMR *amrDataSet = GetAMRDataSet();
AMRCommon::WriteAMRData( amrDataSet, "Gaussian2D" );
amrDataSet->Delete();
return EXIT_SUCCESS;
}
namespace
{
//=============================================================================
// Function Prototype Implementation
//=============================================================================
void SetPulse()
{
Pulse.origin[0] = Pulse.origin[1] = Pulse.origin[2] = -1.0;
Pulse.width[0] = Pulse.width[1] = Pulse.width[2] = 6.0;
Pulse.amplitude = 0.0001;
}
//------------------------------------------------------------------------------
void AttachPulseToGrid( vtkUniformGrid *grid )
{
vtkSmartPointer<vtkDoubleArray> xyz =
vtkSmartPointer<vtkDoubleArray>::New();
xyz->SetName( "GaussianPulse" );
xyz->SetNumberOfComponents( 1 );
xyz->SetNumberOfTuples( grid->GetNumberOfCells() );
for(int cellIdx=0; cellIdx < grid->GetNumberOfCells(); ++cellIdx )
{
double center[3];
AMRCommon::ComputeCellCenter( grid, cellIdx, center );
double r = 0.0;
for( int i=0; i < 2; ++i )
{
double dx = center[i]-Pulse.origin[i];
r += (dx*dx) / (Pulse.width[i]*Pulse.width[i]);
}
double f = Pulse.amplitude*std::exp( -r );
xyz->SetTuple1( cellIdx, f );
} // END for all cells
grid->GetCellData()->AddArray( xyz );
}
//------------------------------------------------------------------------------
vtkOverlappingAMR* GetAMRDataSet()
{
int NumLevels = 2;
int BlocksPerLevel[2] = {1,2};
double origin[3];
origin[0] = origin[1] = -2.0; origin[2] = 0.0;
vtkOverlappingAMR *data = vtkOverlappingAMR::New();
data->Initialize(NumLevels,BlocksPerLevel);
data->SetOrigin(origin);
data->SetGridDescription(VTK_XY_PLANE);
double h[3];
int ndim[3];
// Root Block -- Block 0,0
ndim[0] = 6; ndim[1] = 5; ndim[2] = 1;
h[0] = h[1] = h[2] = 1.0;
int blockId = 0;
int level = 0;
vtkUniformGrid *root = AMRCommon::GetGrid(origin, h, ndim);
vtkAMRBox box(origin, ndim, h, data->GetOrigin(), data->GetGridDescription());
AttachPulseToGrid( root );
data->SetSpacing(level,h);
data->SetAMRBox( level,blockId,box);
data->SetDataSet(level,blockId,root);
root->Delete();
// Block 1,0
ndim[0] = ndim[1] = 9; ndim[2] = 1;
h[0] = h[1] = h[2] = 0.25;
origin[0] = origin[1] = -2.0; origin[2] = 0.0;
blockId = 0;
level = 1;
vtkUniformGrid *grid1 = AMRCommon::GetGrid(origin, h, ndim);
vtkAMRBox box1(origin, ndim, h, data->GetOrigin(), data->GetGridDescription());
AttachPulseToGrid( grid1 );
data->SetSpacing(level,h);
data->SetAMRBox( level,blockId,box1);
data->SetDataSet( level, blockId,grid1);
grid1->Delete();
// Block 1,1
ndim[0] = ndim[1] = 9; ndim[2] = 1;
h[0] = h[1] = h[2] = 0.25;
origin[0] = 1.0; origin[1] = origin[2] = 0.0;
blockId = 1;
level = 1;
vtkUniformGrid *grid3 = AMRCommon::GetGrid(origin, h, ndim);
vtkAMRBox box3(origin, ndim, h, data->GetOrigin(), data->GetGridDescription());
AttachPulseToGrid( grid3 );
data->SetSpacing(level,h);
data->SetAMRBox(level,blockId,box3);
data->SetDataSet( level, blockId,grid3);
grid3->Delete();
vtkAMRUtilities::BlankCells(data);
data->Audit();
return( data );
}
}
namespace AMRCommon {
//------------------------------------------------------------------------------
// Description:
// Writes a uniform grid as a structure grid
void WriteUniformGrid( vtkUniformGrid *g, const std::string &prefix )
{
vtkXMLImageDataWriter *imgWriter = vtkXMLImageDataWriter::New();
std::ostringstream oss;
oss << prefix << "." << imgWriter->GetDefaultFileExtension();
imgWriter->SetFileName( oss.str().c_str() );
imgWriter->SetInputData( g );
imgWriter->Write();
imgWriter->Delete();
}
//------------------------------------------------------------------------------
// Description:
// Writes the given AMR dataset to a *.vth file with the given prefix.
void WriteAMRData( vtkOverlappingAMR *amrData, const std::string &prefix )
{
vtkCompositeDataWriter *writer = vtkCompositeDataWriter::New();
std::ostringstream oss;
oss << prefix << ".vthb";
writer->SetFileName(oss.str().c_str());
writer->SetInputData(amrData);
writer->Write();
writer->Delete();
}
//------------------------------------------------------------------------------
// Description:
// Reads AMR data to the given data-structure from the prescribed file.
vtkHierarchicalBoxDataSet* ReadAMRData( const std::string &file )
{
vtkXMLHierarchicalBoxDataReader *myAMRReader=
vtkXMLHierarchicalBoxDataReader::New();
std::ostringstream oss;
oss.str("");
oss.clear();
oss << file << ".vthb";
std::cout << "Reading AMR Data from: " << oss.str() << std::endl;
std::cout.flush();
myAMRReader->SetFileName( oss.str().c_str() );
myAMRReader->Update();
vtkHierarchicalBoxDataSet *amrData =
vtkHierarchicalBoxDataSet::SafeDownCast( myAMRReader->GetOutput() );
return( amrData );
}
//------------------------------------------------------------------------------
// Description:
// Writes the given multi-block data to an XML file with the prescribed prefix
void WriteMultiBlockData( vtkMultiBlockDataSet *mbds, const std::string &prefix )
{
// Sanity check
vtkXMLMultiBlockDataWriter *writer = vtkXMLMultiBlockDataWriter::New();
std::ostringstream oss;
oss.str(""); oss.clear();
oss << prefix << "." << writer->GetDefaultFileExtension();
writer->SetFileName( oss.str( ).c_str( ) );
writer->SetInputData( mbds );
writer->Write();
writer->Delete();
}
//------------------------------------------------------------------------------
// Constructs a uniform grid instance given the prescribed
// origin, grid spacing and dimensions.
vtkUniformGrid* GetGrid( double* origin,double* h,int* ndim )
{
vtkUniformGrid *grd = vtkUniformGrid::New();
grd->Initialize();
grd->SetOrigin( origin );
grd->SetSpacing( h );
grd->SetDimensions( ndim );
return grd;
}
//------------------------------------------------------------------------------
// Computes the cell center for the cell corresponding to cellIdx w.r.t.
// the given grid. The cell center is stored in the supplied buffer c.
void ComputeCellCenter( vtkUniformGrid *grid, const int cellIdx, double c[3] )
{
vtkCell *myCell = grid->GetCell( cellIdx );
double pCenter[3];
double *weights = new double[ myCell->GetNumberOfPoints() ];
int subId = myCell->GetParametricCenter( pCenter );
myCell->EvaluateLocation( subId,pCenter,c,weights );
delete [] weights;
}
} // END namespace
### Description
This utility code generates a simple 2D AMR dataset with a Gaussian pulse at the center. The resulting AMR dataset is written using the vtkXMLHierarchicalBoxDataSetWriter.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/AMR/Cxx/Generate2DAMRDataSetWithPulse.cxx).
// .NAME Generate3DAMRDataSetWithPulse.cxx -- Generated sample 3D AMR dataset
//
// .SECTION Description
// This utility code generates a simple 3D AMR dataset with a gaussian
// pulse at the center. The resulting AMR dataset is written using the
// vtkXMLHierarchicalBoxDataSetWriter.
#include <iostream>
#include <cmath>
#include <sstream>
#include <vtkAMRUtilities.h>
#include <vtkCell.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDoubleArray.h>
#include <vtkOverlappingAMR.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkUniformGrid.h>
#include <vtkAMRBox.h>
#include <vtkCompositeDataWriter.h>
#include <vtkHierarchicalBoxDataSet.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkXMLHierarchicalBoxDataReader.h>
#include <vtkXMLImageDataWriter.h>
#include <vtkXMLMultiBlockDataWriter.h>
namespace
{
namespace AMRCommon
{
void WriteUniformGrid( vtkUniformGrid *g, const std::string &prefix );
void WriteAMRData( vtkOverlappingAMR *amrData, const std::string &prefix );
vtkHierarchicalBoxDataSet* ReadAMRData( const std::string &file );
void WriteMultiBlockData( vtkMultiBlockDataSet *mbds, const std::string &prefix );
vtkUniformGrid* GetGrid( double* origin,double* h,int* ndim );
void ComputeCellCenter( vtkUniformGrid *grid, const int cellIdx, double c[3] );
}
}
namespace
{
static struct PulseAttributes {
double origin[3]; // xyz for the center of the pulse
double width[3]; // the width of the pulse
double amplitude; // the amplitude of the pulse
} Pulse;
//
// Function prototype declarations
//
// Description:
// Sets the pulse attributes
void SetPulse();
// Description:
// Constructs the vtkHierarchicalBoxDataSet.
vtkOverlappingAMR* GetAMRDataSet();
// Description:
// Attaches the pulse to the given grid.
void AttachPulseToGrid( vtkUniformGrid *grid );
}
//
// Program main
//
int main( int, char *[] )
{
// STEP 0: Initialize gaussian pulse parameters
SetPulse();
// STEP 1: Get the AMR dataset
vtkOverlappingAMR *amrDataSet = GetAMRDataSet();
AMRCommon::WriteAMRData( amrDataSet, "Gaussian3D" );
amrDataSet->Delete();
return 0;
}
namespace
{
//=============================================================================
// Function Prototype Implementation
//=============================================================================
void SetPulse()
{
Pulse.origin[0] = Pulse.origin[1] = Pulse.origin[2] = -1.0;
Pulse.width[0] = Pulse.width[1] = Pulse.width[2] = 6.0;
Pulse.amplitude = 0.0001;
}
//------------------------------------------------------------------------------
void AttachPulseToGrid( vtkUniformGrid *grid )
{
vtkDoubleArray* xyz = vtkDoubleArray::New( );
xyz->SetName( "GaussianPulse" );
xyz->SetNumberOfComponents( 1 );
xyz->SetNumberOfTuples( grid->GetNumberOfCells() );
for(int cellIdx=0; cellIdx < grid->GetNumberOfCells(); ++cellIdx )
{
double center[3];
AMRCommon::ComputeCellCenter( grid, cellIdx, center );
double r = 0.0;
for( int i=0; i < 3; ++i )
{
double dx = center[i]-Pulse.origin[i];
r += (dx*dx) / (Pulse.width[i]*Pulse.width[i]);
}
double f = Pulse.amplitude*std::exp( -r );
xyz->SetTuple1( cellIdx, f );
} // END for all cells
grid->GetCellData()->AddArray( xyz );
xyz->Delete();
}
//------------------------------------------------------------------------------
vtkOverlappingAMR* GetAMRDataSet()
{
vtkOverlappingAMR *data = vtkOverlappingAMR::New();
int blocksPerLevel[2] = {1,3};
double globalOrigin[3] = {-2.0,-2.0,-2.0};
data->Initialize(2,blocksPerLevel);
data->SetOrigin(globalOrigin);
data->SetGridDescription(VTK_XYZ_GRID);
double origin[3];
double h[3];
int ndim[3];
// Root Block -- Block 0
ndim[0] = 6; ndim[1] = ndim[2] = 5;
h[0] = h[1] = h[2] = 1.0;
origin[0] = origin[1] = origin[2] = -2.0;
int blockId = 0;
int level = 0;
vtkUniformGrid *root = AMRCommon::GetGrid(origin,h,ndim);
vtkAMRBox box(origin,ndim,h,data->GetOrigin(), data->GetGridDescription());
AttachPulseToGrid( root );
data->SetAMRBox(level,blockId,box);
data->SetDataSet( level, blockId,root);
root->Delete();
// Block 1
ndim[0] = 3; ndim[1] = ndim[2] = 5;
h[0] = h[1] = h[2] = 0.5;
origin[0] = origin[1] = origin[2] = -2.0;
blockId = 0;
level = 1;
vtkUniformGrid *grid1 = AMRCommon::GetGrid(origin,h,ndim);
AttachPulseToGrid(grid1);
vtkAMRBox box1(origin,ndim,h,data->GetOrigin(), data->GetGridDescription());
data->SetAMRBox(level,blockId,box1);
data->SetDataSet(level, blockId,grid1);
grid1->Delete();
// Block 2
ndim[0] = 3; ndim[1] = ndim[2] = 5;
h[0] = h[1] = h[2] = 0.5;
origin[0] = 0.0; origin[1] = origin[2] = -1.0;
blockId = 1;
level = 1;
vtkUniformGrid *grid2 = AMRCommon::GetGrid(origin,h,ndim);
AttachPulseToGrid(grid2);
vtkAMRBox box2(origin,ndim,h,data->GetOrigin(), data->GetGridDescription());
data->SetAMRBox(level,blockId,box2);
data->SetDataSet(level,blockId,grid2);
grid2->Delete();
// Block 3
ndim[0] = 3; ndim[1] = ndim[2] = 7;
h[0] = h[1] = h[2] = 0.5;
origin[0] = 2.0; origin[1] = origin[2] = -1.0;
blockId = 2;
level = 1;
vtkUniformGrid *grid3 = AMRCommon::GetGrid(origin,h,ndim);
vtkAMRBox box3(origin,ndim,h,data->GetOrigin(), data->GetGridDescription());
AttachPulseToGrid(grid3);
data->SetAMRBox(level,blockId,box3);
data->SetDataSet( level, blockId,grid3);
grid3->Delete();
vtkAMRUtilities::BlankCells(data);
return( data );
}
}
namespace
{
namespace AMRCommon {
//------------------------------------------------------------------------------
// Description:
// Writes a uniform grid as a structure grid
void WriteUniformGrid( vtkUniformGrid *g, const std::string &prefix )
{
vtkXMLImageDataWriter *imgWriter = vtkXMLImageDataWriter::New();
std::ostringstream oss;
oss << prefix << "." << imgWriter->GetDefaultFileExtension();
imgWriter->SetFileName( oss.str().c_str() );
imgWriter->SetInputData( g );
imgWriter->Write();
imgWriter->Delete();
}
//------------------------------------------------------------------------------
// Description:
// Writes the given AMR dataset to a *.vth file with the given prefix.
void WriteAMRData( vtkOverlappingAMR *amrData, const std::string &prefix )
{
vtkCompositeDataWriter *writer = vtkCompositeDataWriter::New();
std::ostringstream oss;
oss << prefix << ".vthb";
writer->SetFileName(oss.str().c_str());
writer->SetInputData(amrData);
writer->Write();
writer->Delete();
}
//------------------------------------------------------------------------------
// Description:
// Reads AMR data to the given data-structure from the prescribed file.
vtkHierarchicalBoxDataSet* ReadAMRData( const std::string &file )
{
vtkXMLHierarchicalBoxDataReader *myAMRReader=
vtkXMLHierarchicalBoxDataReader::New();
std::ostringstream oss;
oss.str("");
oss.clear();
oss << file << ".vthb";
std::cout << "Reading AMR Data from: " << oss.str() << std::endl;
std::cout.flush();
myAMRReader->SetFileName( oss.str().c_str() );
myAMRReader->Update();
vtkHierarchicalBoxDataSet *amrData =
vtkHierarchicalBoxDataSet::SafeDownCast( myAMRReader->GetOutput() );
return( amrData );
}
//------------------------------------------------------------------------------
// Description:
// Writes the given multi-block data to an XML file with the prescribed prefix
void WriteMultiBlockData( vtkMultiBlockDataSet *mbds, const std::string &prefix )
{
// Sanity check
vtkXMLMultiBlockDataWriter *writer = vtkXMLMultiBlockDataWriter::New();
std::ostringstream oss;
oss.str(""); oss.clear();
oss << prefix << "." << writer->GetDefaultFileExtension();
writer->SetFileName( oss.str( ).c_str( ) );
writer->SetInputData( mbds );
writer->Write();
writer->Delete();
}
//------------------------------------------------------------------------------
// Constructs a uniform grid instance given the prescribed
// origin, grid spacing and dimensions.
vtkUniformGrid* GetGrid( double* origin,double* h,int* ndim )
{
vtkUniformGrid *grd = vtkUniformGrid::New();
grd->Initialize();
grd->SetOrigin( origin );
grd->SetSpacing( h );
grd->SetDimensions( ndim );
return grd;
}
//------------------------------------------------------------------------------
// Computes the cell center for the cell corresponding to cellIdx w.r.t.
// the given grid. The cell center is stored in the supplied buffer c.
void ComputeCellCenter( vtkUniformGrid *grid, const int cellIdx, double c[3] )
{
vtkCell *myCell = grid->GetCell( cellIdx );
double pCenter[3];
double *weights = new double[ myCell->GetNumberOfPoints() ];
int subId = myCell->GetParametricCenter( pCenter );
myCell->EvaluateLocation( subId,pCenter,c,weights );
delete [] weights;
}
}
}
### Description
This utility code generates a simple 3D AMR dataset with a Gaussian pulse at the center. The resulting AMR dataset is written using the vtkXMLHierarchicalBoxDataSetWriter.
!!! note
The original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/AMR/Cxx/Generate3DAMRDataSetWithPulse.cxx).
// This example demonstrates how hierarchical box (uniform rectilinear)
// AMR datasets can be processed using the new vtkHierarchicalBoxDataSet class.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
// -D <path> => path to the data; the data should be in <path>/Data/
#include <vtkSmartPointer.h>
#include <vtkCamera.h>
#include <vtkCellDataToPointData.h>
#include <vtkCompositeDataPipeline.h>
#include <vtkContourFilter.h>
#include <vtkExtractLevel.h>
#include <vtkHierarchicalDataSetGeometryFilter.h>
#include <vtkOutlineCornerFilter.h>
#include <vtkHierarchicalPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkShrinkPolyData.h>
#include <vtkXMLHierarchicalBoxDataReader.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " file.vtm" << std::endl;
return EXIT_FAILURE;
}
// Standard rendering classes
vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::New();
vtkCamera* cam = ren->GetActiveCamera();
cam->SetPosition(-5.1828, 5.89733, 8.97969);
cam->SetFocalPoint(14.6491, -2.08677, -8.92362);
cam->SetViewUp(0.210794, 0.95813, -0.193784);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkXMLHierarchicalBoxDataReader> reader =
vtkSmartPointer<vtkXMLHierarchicalBoxDataReader>::New();
reader->SetFileName(argv[1]);
// geometry filter
vtkSmartPointer<vtkHierarchicalDataSetGeometryFilter> geom =
vtkSmartPointer<vtkHierarchicalDataSetGeometryFilter>::New();
geom->SetInputConnection(0, reader->GetOutputPort(0));
vtkSmartPointer<vtkShrinkPolyData> shrink =
vtkSmartPointer<vtkShrinkPolyData>::New();
shrink->SetShrinkFactor(0.5);
shrink->SetInputConnection(0, geom->GetOutputPort(0));
return EXIT_SUCCESS;
// Rendering objects
vtkSmartPointer<vtkHierarchicalPolyDataMapper> shMapper =
vtkSmartPointer<vtkHierarchicalPolyDataMapper>::New();
shMapper->SetInputConnection(0, shrink->GetOutputPort(0));
vtkSmartPointer<vtkActor> shActor =
vtkSmartPointer<vtkActor>::New();
shActor->SetMapper(shMapper);
shActor->GetProperty()->SetColor(0, 0, 1);
ren->AddActor(shActor);
// corner outline
vtkSmartPointer<vtkOutlineCornerFilter> ocf =
vtkSmartPointer<vtkOutlineCornerFilter>::New();
vtkSmartPointer<vtkCompositeDataPipeline> pipeline =
vtkSmartPointer<vtkCompositeDataPipeline>::New();
ocf->SetExecutive(pipeline);
ocf->SetInputConnection(0, reader->GetOutputPort(0));
// Rendering objects
// This one is actually just a vtkPolyData so it doesn't need a hierarchical
// mapper, but we use this one to test hierarchical mapper with polydata input
vtkSmartPointer<vtkHierarchicalPolyDataMapper> ocMapper =
vtkSmartPointer<vtkHierarchicalPolyDataMapper>::New();
ocMapper->SetInputConnection(0, ocf->GetOutputPort(0));
vtkSmartPointer<vtkActor> ocActor =
vtkSmartPointer<vtkActor>::New();
ocActor->SetMapper(ocMapper);
ocActor->GetProperty()->SetColor(1, 0, 0);
ren->AddActor(ocActor);
// cell 2 point and contour
vtkSmartPointer<vtkExtractLevel> el =
vtkSmartPointer<vtkExtractLevel>::New();
el->SetInputConnection(0, reader->GetOutputPort(0));
el->AddLevel(2);
vtkSmartPointer<vtkCellDataToPointData> c2p =
vtkSmartPointer<vtkCellDataToPointData>::New();
pipeline = vtkCompositeDataPipeline::New();
c2p->SetExecutive(pipeline);
c2p->SetInputConnection(0, el->GetOutputPort(0));
vtkSmartPointer<vtkContourFilter> contour =
vtkSmartPointer<vtkContourFilter>::New();
pipeline = vtkCompositeDataPipeline::New();
contour->SetExecutive(pipeline);
contour->SetInputConnection(0, c2p->GetOutputPort(0));
contour->SetValue(0, -0.013);
contour->SetInputArrayToProcess(
0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS,"phi");
// Rendering
vtkSmartPointer<vtkHierarchicalPolyDataMapper> contMapper =
vtkSmartPointer<vtkHierarchicalPolyDataMapper>::New();
contMapper->SetInputConnection(0, contour->GetOutputPort(0));
vtkSmartPointer<vtkActor> contActor =
vtkSmartPointer<vtkActor>::New();
contActor->SetMapper(contMapper);
contActor->GetProperty()->SetColor(1, 0, 0);
ren->AddActor(contActor);
ren->SetBackground(1,1,1);
renWin->SetSize(300,300);
ren->ResetCamera();
iren->Start();
return EXIT_SUCCESS;
}
### Description
This example demonstrates how hierarchical box (uniform rectilinear) AMR datasets can be processed using the new vtkHierarchicalBoxDataSet class.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/AMR/Cxx/HierarchicalBoxPipeline.cxx).
### Description
This example reports the cell, cell data and point data contained within a VTK XML or legacy file.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/IO/Cxx/DumpXMLFile.cxx).
......@@ -4,3 +4,6 @@ any post processing. This example converts the point data from a
labeled volume into cell data. The surfaces are displayed as
polydata. If you want to created smoothed polydata models from your
segmented volumes, see the example [GenerateModelsFromLabels](/Cxx/Medical/GenerateModelsFromLabels). The input volume must be in [MetaIO format](http://www.vtk.org/Wiki/MetaIO/Documentation).
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/GenerateCubesFromLabels.cxx).
......@@ -9,3 +9,6 @@ cube models, see the example [GenerateCubesFromLabels](/Cxx/Medical/GenerateCube
The input volume must be in [MetaIO format](http://www.vtk.org/Wiki/MetaIO/Documentation).
Once you generate the models, you can view them with [Paraview](http://paraview.org)
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/GenerateModelsFromLabels.cxx).
### Description
The skin extracted from a CT dataset of the head.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/Medical1.cxx).
### Description
Skin and bone isosurfaces.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/Medical2.cxx).
### Description
Composite image of three planes and translucent skin
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/Medical3.cxx).
### Description
Volume rendering of the dataset.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Medical/Cxx/Medical4.cxx).
......@@ -7,3 +7,6 @@ The example requires a .vtp file and an optional alpha.
!!! seealso
See [Delaunay3DDemo](/Cxx/Modelling/Delaunay3DDemo) to interactively adjust Alpha.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/395857190c8453508d283958383bc38c9c2999bf/Examples/Modelling/Cxx/Delaunay3D.cxx).
\ No newline at end of file
### Description
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/73465690278158b9e89661cd6aed26bead781378/Examples/Rendering/Cxx/AmbientSpheres.cxx).
......@@ -27,6 +27,14 @@ if (BUILD_TESTING)
# Testing
SET(KIT Rendering)
SET(NEEDS_ARGS
Rainbow
)
SET(DATA ${WikiExamples_SOURCE_DIR}/src/Testing/Data)
SET(TEMP ${WikiExamples_BINARY_DIR}/Testing/Temporary)
ADD_TEST(${KIT}-Rainbow ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${KIT}CxxTests
TestRainbow ${DATA}/combxyz.bin ${DATA}/combq.bin)
INCLUDE(${WikiExamples_SOURCE_DIR}/CMake/ExamplesTesting.cmake)
endif()
......@@ -2,3 +2,6 @@ This example creates a minimal visualization program, demonstrating VTK's basic
!!! seealso
[Java](/Java) and [Python](/Python) versions of this example.
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/73465690278158b9e89661cd6aed26bead781378/Examples/Rendering/Cxx/Cylinder.cxx).
### Description
!!! note
This original source code for this example is [here](https://gitlab.kitware.com/vtk/vtk/blob/73465690278158b9e89661cd6aed26bead781378/Examples/Rendering/Cxx/DiffuseSpheres.cxx).
#include <vtkSmartPointer.h>
#include <vtkMultiBlockPLOT3DReader.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkActor.h>
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkLookupTable.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkStructuredGrid.h>
#include <vtkStructuredGridGeometryFilter.h>
#include <vtkStructuredGridOutlineFilter.h>
#include <vtkNamedColors.h>
// This example demonstrates the use and manipulation of lookup tables.
// First create pipeline a simple pipeline that reads a structure grid
// and then extracts a plane from the grid. The plane will be colored
// differently by using different lookup tables.
//
// Note: the Update method is manually invoked because it causes the
// reader to read; later on we use the output of the reader to set
// a range for the scalar values.
int main (int argc, char *argv[])
{
if (argc < 3)
{
std::cout << "Usage: " << argv[0] << " file.xyz file.bin" << std::endl;
return EXIT_FAILURE;
}
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
vtkSmartPointer<vtkMultiBlockPLOT3DReader> pl3d =
vtkSmartPointer<vtkMultiBlockPLOT3DReader>::New();
pl3d->SetXYZFileName(argv[1]);
pl3d->SetQFileName(argv[2]);
pl3d->SetScalarFunctionNumber(100);
pl3d->SetVectorFunctionNumber(202);
pl3d->Update();
vtkStructuredGrid *pl3dOutput =
vtkStructuredGrid::SafeDownCast(pl3d->GetOutput()->GetBlock(0));
vtkSmartPointer<vtkStructuredGridGeometryFilter> plane =
vtkSmartPointer<vtkStructuredGridGeometryFilter>::New();
plane->SetInputData(pl3dOutput);
plane->SetExtent( 1, 100, 1, 100, 7, 7);
vtkSmartPointer<vtkLookupTable> lut =
vtkSmartPointer<vtkLookupTable>::New();
vtkSmartPointer<vtkPolyDataMapper> planeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
planeMapper->SetLookupTable(lut);
planeMapper->SetInputConnection(plane->GetOutputPort());
planeMapper->SetScalarRange(pl3dOutput->GetScalarRange());
vtkSmartPointer<vtkActor> planeActor =
vtkSmartPointer<vtkActor>::New();
planeActor->SetMapper(planeMapper);
// This creates an outline around the data.
vtkSmartPointer<vtkStructuredGridOutlineFilter> outline =
vtkSmartPointer<vtkStructuredGridOutlineFilter>::New();
outline->SetInputData(pl3dOutput);
vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
vtkSmartPointer<vtkActor> outlineActor =
vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
// Much of the following is commented out. To try different lookup tables,
// uncommented the appropriate portions.
//
// This creates a black to white lut.
// lut SetHueRange 0 0
// lut SetSaturationRange 0 0
// lut SetValueRange 0.2 1.0
// This creates a red to blue lut.
// lut SetHueRange 0.0 0.667
// This creates a blue to red lut.
// lut SetHueRange 0.667 0.0
// This creates a weird effect. The Build() method causes the lookup table
// to allocate memory and create a table based on the currect hue, saturation,
// value, and alpha (transparency) range. Here we then manually overwrite the
// values generated by the Build() method.
lut->SetNumberOfColors(256);
lut->SetHueRange(0.0, 0.667 );
lut->Build();
// Create the RenderWindow, Renderer and both Actors
//
vtkSmartPointer<vtkRenderer> ren1 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
// Add the actors to the renderer, set the background and size
//
ren1->AddActor(outlineActor);
ren1->AddActor(planeActor);
ren1->SetBackground(colors->GetColor3d("SlateGray").GetData());
ren1->TwoSidedLightingOff();
renWin->SetSize( 512, 512);
iren->Initialize();
vtkCamera *cam1 = ren1->GetActiveCamera();
cam1->SetClippingRange( 3.95297, 50);
cam1->SetFocalPoint( 8.88908, 0.595038, 29.3342);
cam1->SetPosition( -12.3332, 31.7479, 41.2387);
cam1->SetViewUp(0.060772, -0.319905, 0.945498);
iren->Start();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment