36 #include <boost/filesystem.hpp> 37 #include <boost/lexical_cast.hpp> 38 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning 39 #include <vtkPoints.h> 40 #include <vtkPolyData.h> 41 #include <vtkPolyDataMapper.h> 43 #include <vtkProperty.h> 44 #include <vtkUnsignedCharArray.h> 45 #if VTK_MAJOR_VERSION > 5 46 #include <vtkNamedColors.h> 48 #if VTK_MAJOR_VERSION > 5 49 #include <vtkAutoInit.h> 50 VTK_MODULE_INIT(vtkRenderingOpenGL);
51 VTK_MODULE_INIT(vtkRenderingFreeType);
52 #include <vtkOggTheoraWriter.h> 54 #include <vtkSphereSource.h> 55 #include <vtkGlyph3D.h> 56 #include <vtkGlyph2D.h> 57 #include <vtkCubeAxesActor2D.h> 58 #include <vtkImageData.h> 59 #include <vtkGeometryFilter.h> 60 #include <vtkTubeFilter.h> 61 #include <vtkExtractEdges.h> 62 #include <vtkUnstructuredGrid.h> 64 #include <vtkPolygon.h> 65 #include <vtkIdList.h> 66 #include <vtkFeatureEdges.h> 67 #include <vtkColorTransferFunction.h> 68 #include <vtkScalarBarActor.h> 69 #include <vtkTextProperty.h> 70 #include "UblasIncludes.hpp" 71 #include "UblasVectorInclude.hpp" 72 #include "Exception.hpp" 73 #include "BaseUnits.hpp" 74 #include "VesselNetworkWriter.hpp" 76 #include "RegularGridActorGenerator.hpp" 78 template<
unsigned DIM>
83 mUseTubesForEdges(false)
88 template<
unsigned DIM>
94 template<
unsigned DIM>
99 vtkSmartPointer<vtkImageData> p_grid =
mpRegularGrid->GetVtkGrid();
101 vtkSmartPointer<vtkGeometryFilter> p_geom_filter = vtkSmartPointer<vtkGeometryFilter>::New();
102 #if VTK_MAJOR_VERSION <= 5 103 p_geom_filter->SetInput(p_grid);
105 p_geom_filter->SetInputData(p_grid);
108 vtkSmartPointer<vtkColorTransferFunction> p_scaled_ctf = vtkSmartPointer<vtkColorTransferFunction>::New();
109 if(!this->mDataLabel.empty())
112 p_grid->GetPointData()->GetArray(this->mDataLabel.c_str())->GetRange(range);
113 for(
unsigned idx=0; idx<256; idx++)
117 p_scaled_ctf->AddRGBPoint(range[0] +
double(idx)*(range[1]-range[0])/255.0, color[0], color[1], color[2]);
124 vtkSmartPointer<vtkSphereSource> p_spheres = vtkSmartPointer<vtkSphereSource>::New();
125 p_spheres->SetRadius(this->mPointSize);
126 p_spheres->SetPhiResolution(16);
127 p_spheres->SetThetaResolution(16);
129 vtkSmartPointer<vtkGlyph3D> p_glyph = vtkSmartPointer<vtkGlyph3D>::New();
130 #if VTK_MAJOR_VERSION <= 5 131 p_glyph->SetInputConnection(p_geom_filter->GetOutputPort());
132 p_glyph->SetSource(p_spheres->GetOutput());
134 p_glyph->SetInputConnection(p_geom_filter->GetOutputPort());
135 p_glyph->SetSourceConnection(p_spheres->GetOutputPort());
137 p_glyph->ClampingOff();
138 p_glyph->SetScaleModeToScaleByScalar();
139 p_glyph->SetScaleFactor(1.0);
142 vtkSmartPointer<vtkPolyDataMapper> p_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
143 #if VTK_MAJOR_VERSION <= 5 144 p_mapper->SetInput(p_glyph->GetOutput());
146 p_mapper->SetInputData(p_glyph->GetOutput());
148 p_mapper->ScalarVisibilityOn();
150 vtkSmartPointer<vtkActor> p_actor = vtkSmartPointer<vtkActor>::New();
151 p_actor->SetMapper(p_mapper);
153 pRenderer->AddActor(p_actor);
159 vtkSmartPointer<vtkFeatureEdges> p_edges = vtkSmartPointer<vtkFeatureEdges>::New();
160 p_edges->SetInputConnection(p_geom_filter->GetOutputPort());
161 p_edges->SetFeatureEdges(
false);
162 p_edges->SetBoundaryEdges(
true);
163 p_edges->SetManifoldEdges(
true);
164 p_edges->SetNonManifoldEdges(
false);
166 if(mUseTubesForEdges)
168 vtkSmartPointer<vtkTubeFilter> p_voronoi_tubes = vtkSmartPointer<vtkTubeFilter>::New();
169 p_voronoi_tubes->SetInputConnection(p_edges->GetOutputPort());
170 p_voronoi_tubes->SetRadius(this->mEdgeSize);
171 p_voronoi_tubes->SetNumberOfSides(12);
173 vtkSmartPointer<vtkPolyDataMapper> p_voronoi_tube_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
174 p_voronoi_tube_mapper->SetInputConnection(p_voronoi_tubes->GetOutputPort());
176 vtkSmartPointer<vtkActor> p_voronoi_tube_actor = vtkSmartPointer<vtkActor>::New();
177 p_voronoi_tube_actor->SetMapper(p_voronoi_tube_mapper);
179 p_voronoi_tube_actor->GetProperty()->SetOpacity(this->
mVolumeOpacity);
180 pRenderer->AddActor(p_voronoi_tube_actor);
184 vtkSmartPointer<vtkPolyDataMapper> p_edge_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
185 p_edge_mapper->SetInputConnection(p_edges->GetOutputPort());
186 p_edge_mapper->ScalarVisibilityOff();
188 vtkSmartPointer<vtkActor> p_edge_actor = vtkSmartPointer<vtkActor>::New();
189 p_edge_actor->SetMapper(p_edge_mapper);
192 pRenderer->AddActor(p_edge_actor);
199 vtkSmartPointer<vtkPolyDataMapper> p_grid_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
200 p_grid_mapper->SetInputConnection(p_geom_filter->GetOutputPort());
201 if(!this->mDataLabel.empty())
203 p_grid_mapper->SetLookupTable(p_scaled_ctf);
204 p_grid_mapper->ScalarVisibilityOn();
206 p_grid_mapper->SelectColorArray(this->mDataLabel.c_str());
207 p_grid_mapper->SetScalarModeToUsePointFieldData();
208 p_grid_mapper->SetColorModeToMapScalars();
212 vtkSmartPointer<vtkActor> p_volume_actor = vtkSmartPointer<vtkActor>::New();
213 p_volume_actor->SetMapper(p_grid_mapper);
214 p_volume_actor->GetProperty()->SetEdgeVisibility(1);
215 p_volume_actor->GetProperty()->SetLineWidth(this->mEdgeSize);
216 if(this->mDataLabel.empty())
221 pRenderer->AddActor(p_volume_actor);
223 if(!this->mDataLabel.empty())
225 vtkSmartPointer<vtkScalarBarActor> p_scale_bar = vtkSmartPointer<vtkScalarBarActor>::New();
226 p_scale_bar->SetLookupTable(p_scaled_ctf);
227 p_scale_bar->SetTitle(this->mDataLabel.c_str());
228 p_scale_bar->SetOrientationToHorizontal();
229 p_scale_bar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
230 p_scale_bar->GetPositionCoordinate()->SetValue(0.25, 0.84);
231 p_scale_bar->SetWidth(0.5);
232 p_scale_bar->SetHeight(0.1);
233 p_scale_bar->GetTitleTextProperty()->ItalicOff();
234 p_scale_bar->GetLabelTextProperty()->ItalicOff();
235 p_scale_bar->GetTitleTextProperty()->BoldOff();
236 p_scale_bar->GetLabelTextProperty()->BoldOff();
237 p_scale_bar->SetLabelFormat(
"%.2g");
238 p_scale_bar->GetTitleTextProperty()->SetFontSize(5.0);
239 p_scale_bar->GetLabelTextProperty()->SetFontSize(5.0);
240 p_scale_bar->GetTitleTextProperty()->SetColor(0.0, 0.0, 0.0);
241 p_scale_bar->GetLabelTextProperty()->SetColor(0.0, 0.0, 0.0);
242 pRenderer->AddActor(p_scale_bar);
248 template<
unsigned DIM>
254 template<
unsigned DIM>
c_vector< double, 3 > mEdgeColor
boost::shared_ptr< RegularGrid< DIM > > mpRegularGrid
void SetRegularGrid(boost::shared_ptr< RegularGrid< DIM > > pRegularGrid)
void SetEdgeOpacity(double opacity)
void AddActor(vtkSmartPointer< vtkRenderer > pRenderer)
c_vector< double, 3 > mPointColor
vtkSmartPointer< vtkColorTransferFunction > mpColorTransferFunction
RegularGridActorGenerator()
~RegularGridActorGenerator()
c_vector< double, 3 > mVolumeColor