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 #include <vtkSphereSource.h> 49 #include <vtkGlyph3D.h> 50 #include <vtkGlyph2D.h> 51 #include <vtkCubeAxesActor2D.h> 52 #include <vtkImageData.h> 53 #include <vtkGeometryFilter.h> 54 #include <vtkTubeFilter.h> 55 #include <vtkExtractEdges.h> 56 #include <vtkUnstructuredGrid.h> 58 #include <vtkPolygon.h> 59 #include <vtkIdList.h> 60 #include <vtkFeatureEdges.h> 61 #include "UblasIncludes.hpp" 62 #include "UblasVectorInclude.hpp" 63 #include "Exception.hpp" 64 #include "BaseUnits.hpp" 65 #include "VesselNetworkWriter.hpp" 67 #include "CellPopulationActorGenerator.hpp" 70 template<
unsigned DIM>
78 template<
unsigned DIM>
84 template<
unsigned DIM>
90 if(boost::dynamic_pointer_cast<MeshBasedCellPopulation<DIM> >(
mpCellPopulation))
97 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
98 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
100 for (
typename AbstractCellPopulation<DIM>::Iterator cell_iter =
mpCellPopulation->Begin();
103 c_vector<double, DIM> centre =
mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
106 p_points->InsertNextPoint(centre[0], centre[1], centre[2]);
110 p_points->InsertNextPoint(centre[0], centre[1], 0.0);
113 p_polydata->SetPoints(p_points);
115 vtkSmartPointer<vtkSphereSource> p_spheres = vtkSmartPointer<vtkSphereSource>::New();
116 p_spheres->SetRadius(0.5);
117 p_spheres->SetPhiResolution(16);
118 p_spheres->SetThetaResolution(16);
120 vtkSmartPointer<vtkGlyph3D> p_glyph = vtkSmartPointer<vtkGlyph3D>::New();
121 #if VTK_MAJOR_VERSION <= 5 122 p_glyph->SetInput(p_polydata);
123 p_glyph->SetSource(p_spheres->GetOutput());
125 p_glyph->SetInputData(p_polydata);
126 p_glyph->SetSourceConnection(p_spheres->GetOutputPort());
128 p_glyph->ClampingOff();
129 p_glyph->SetScaleModeToScaleByScalar();
130 p_glyph->SetScaleFactor(1.0);
133 vtkSmartPointer<vtkPolyDataMapper> p_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
134 #if VTK_MAJOR_VERSION <= 5 135 p_mapper->SetInput(p_glyph->GetOutput());
137 p_mapper->SetInputData(p_glyph->GetOutput());
139 p_mapper->ScalarVisibilityOff();
141 vtkSmartPointer<vtkActor> p_actor = vtkSmartPointer<vtkActor>::New();
142 p_actor->SetMapper(p_mapper);
143 p_actor->GetProperty()->SetColor(0,1,0);
144 pRenderer->AddActor(p_actor);
149 template<
unsigned DIM>
152 boost::shared_ptr<MeshBasedCellPopulation<DIM> > p_cell_population = boost::dynamic_pointer_cast<MeshBasedCellPopulation<DIM> >(
mpCellPopulation);
154 if(!p_cell_population)
156 EXCEPTION(
"Could not cast mesh to MeshBased type.");
160 p_cell_population->CreateVoronoiTessellation();
161 vtkSmartPointer<vtkUnstructuredGrid> p_voronoi_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
163 if(p_cell_population->GetVoronoiTessellation() != NULL)
165 vtkSmartPointer<vtkPoints> p_points = vtkSmartPointer<vtkPoints>::New();
166 p_points->GetData()->SetName(
"Vertex positions");
167 for (
unsigned node_num=0; node_num<p_cell_population->GetVoronoiTessellation()->GetNumNodes(); node_num++)
169 c_vector<double, DIM> position = p_cell_population->GetVoronoiTessellation()->GetNode(node_num)->rGetLocation();
172 p_points->InsertPoint(node_num, position[0], position[1], 0.0);
176 p_points->InsertPoint(node_num, position[0], position[1], position[2]);
179 p_voronoi_grid->SetPoints(p_points);
181 for (
typename VertexMesh<DIM,DIM>::VertexElementIterator iter = p_cell_population->GetVoronoiTessellation()->GetElementIteratorBegin();
182 iter != p_cell_population->GetVoronoiTessellation()->GetElementIteratorEnd(); ++iter)
184 vtkSmartPointer<vtkCell> p_cell;
187 p_cell = vtkSmartPointer<vtkPolygon>::New();
191 p_cell = vtkSmartPointer<vtkConvexPointSet>::New();
193 vtkSmartPointer<vtkIdList> p_cell_id_list = p_cell->GetPointIds();
194 p_cell_id_list->SetNumberOfIds(iter->GetNumNodes());
195 for (
unsigned j=0; j<iter->GetNumNodes(); ++j)
197 p_cell_id_list->SetId(j, iter->GetNodeGlobalIndex(j));
199 p_voronoi_grid->InsertNextCell(p_cell->GetCellType(), p_cell_id_list);
203 vtkSmartPointer<vtkGeometryFilter> p_geom_filter = vtkSmartPointer<vtkGeometryFilter>::New();
204 #if VTK_MAJOR_VERSION <= 5 205 p_geom_filter->SetInput(p_voronoi_grid);
207 p_geom_filter->SetInputData(p_voronoi_grid);
210 vtkSmartPointer<vtkPolyDataMapper> p_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
211 p_mapper->SetInputConnection(p_geom_filter->GetOutputPort());
212 p_mapper->ScalarVisibilityOff();
214 vtkSmartPointer<vtkActor> p_actor = vtkSmartPointer<vtkActor>::New();
215 p_actor->SetMapper(p_mapper);
216 p_actor->GetProperty()->SetColor(1,1,0);
217 p_actor->GetProperty()->SetOpacity(0.8);
218 pRenderer->AddActor(p_actor);
220 vtkSmartPointer<vtkFeatureEdges> p_voronoi_extract_edges = vtkSmartPointer<vtkFeatureEdges>::New();
221 p_voronoi_extract_edges->SetInputConnection(p_geom_filter->GetOutputPort());
222 p_voronoi_extract_edges->SetFeatureEdges(
false);
223 p_voronoi_extract_edges->SetBoundaryEdges(
true);
224 p_voronoi_extract_edges->SetManifoldEdges(
true);
225 p_voronoi_extract_edges->SetNonManifoldEdges(
false);
227 vtkSmartPointer<vtkTubeFilter> p_voronoi_tubes = vtkSmartPointer<vtkTubeFilter>::New();
228 p_voronoi_tubes->SetInputConnection(p_voronoi_extract_edges->GetOutputPort());
229 p_voronoi_tubes->SetRadius(0.006);
230 p_voronoi_tubes->SetNumberOfSides(12);
232 vtkSmartPointer<vtkPolyDataMapper> p_voronoi_tube_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
233 p_voronoi_tube_mapper->SetInputConnection(p_voronoi_tubes->GetOutputPort());
234 p_voronoi_tube_mapper->ScalarVisibilityOff();
236 vtkSmartPointer<vtkActor> p_voronoi_tube_actor = vtkSmartPointer<vtkActor>::New();
237 p_voronoi_tube_actor->SetMapper(p_voronoi_tube_mapper);
238 p_voronoi_tube_actor->GetProperty()->SetColor(0,0,0);
239 pRenderer->AddActor(p_voronoi_tube_actor);
324 vtkSmartPointer<vtkPoints> p_centres_points = vtkSmartPointer<vtkPoints>::New();
325 vtkSmartPointer<vtkPolyData> p_polydata = vtkSmartPointer<vtkPolyData>::New();
327 for (
typename AbstractCellPopulation<DIM>::Iterator cell_iter =
mpCellPopulation->Begin();
330 c_vector<double, DIM> centre =
mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
333 p_centres_points->InsertNextPoint(centre[0], centre[1], centre[2]);
337 p_centres_points->InsertNextPoint(centre[0], centre[1], 0.0);
340 p_polydata->SetPoints(p_centres_points);
342 vtkSmartPointer<vtkSphereSource> p_spheres = vtkSmartPointer<vtkSphereSource>::New();
343 p_spheres->SetRadius(0.1);
344 p_spheres->SetPhiResolution(16);
345 p_spheres->SetThetaResolution(16);
347 vtkSmartPointer<vtkGlyph3D> p_glyph = vtkSmartPointer<vtkGlyph3D>::New();
348 #if VTK_MAJOR_VERSION <= 5 349 p_glyph->SetInput(p_polydata);
350 p_glyph->SetSource(p_spheres->GetOutput());
352 p_glyph->SetInputData(p_polydata);
353 p_glyph->SetSourceConnection(p_spheres->GetOutputPort());
355 p_glyph->ClampingOff();
356 p_glyph->SetScaleModeToScaleByScalar();
357 p_glyph->SetScaleFactor(1.0);
360 vtkSmartPointer<vtkPolyDataMapper> p_centres_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
361 #if VTK_MAJOR_VERSION <= 5 362 p_centres_mapper->SetInput(p_glyph->GetOutput());
364 p_centres_mapper->SetInputData(p_glyph->GetOutput());
366 p_centres_mapper->ScalarVisibilityOff();
368 vtkSmartPointer<vtkActor> p_centres_actor = vtkSmartPointer<vtkActor>::New();
369 p_centres_actor->SetMapper(p_centres_mapper);
370 p_centres_actor->GetProperty()->SetColor(0.6,0.0,0.0);
371 pRenderer->AddActor(p_centres_actor);
375 template<
unsigned DIM>
void SetCellPopulation(boost::shared_ptr< AbstractCellPopulation< DIM > > pCellPopulation)
void AddMeshBasedCellPopulationActor(vtkSmartPointer< vtkRenderer > pRenderer)
boost::shared_ptr< AbstractCellPopulation< DIM > > mpCellPopulation
void AddActor(vtkSmartPointer< vtkRenderer > pRenderer)
~CellPopulationActorGenerator()
CellPopulationActorGenerator()