36 #include "Exception.hpp" 37 #include "ImageToMesh.hpp" 38 #include <vtkThreshold.h> 39 #include <vtkGeometryFilter.h> 40 #include <vtkMarchingCubes.h> 41 #include <vtkTriangleFilter.h> 42 #include <vtkPoints.h> 43 #include <vtkPolyData.h> 44 #include <vtkProbeFilter.h> 45 #include "ImageToSurface.hpp" 46 #include "SurfaceCleaner.hpp" 47 #include "BoundaryExtractor.hpp" 48 #include "UblasIncludes.hpp" 49 #include "GeometryWriter.hpp" 50 #include "DiscreteContinuumMeshGenerator.hpp" 51 #include "BaseUnits.hpp" 53 template<
unsigned DIM>
55 : mpImage(vtkSmartPointer<vtkImageData>::New()),
56 mElementSize(0.0 *
unit::metres *
unit::metres*
unit::metres),
63 template<
unsigned DIM>
70 template<
unsigned DIM>
76 template<
unsigned DIM>
85 EXCEPTION(
"No mesh set. Did you run 'Update()' ?");
89 template<
unsigned DIM>
95 template<
unsigned DIM>
101 template<
unsigned DIM>
107 template<
unsigned DIM>
114 template<
unsigned DIM>
119 EXCEPTION(
"No input set.");
123 image_to_surface.SetInput(
mpImage);
124 image_to_surface.SetThreshold(1.0,
false);
125 image_to_surface.Update();
128 extractor.
SetInput(image_to_surface.GetOutput());
141 temp_mesh_generator.
Update();
142 boost::shared_ptr<DiscreteContinuumMesh<DIM, DIM> > p_temp_mesh = temp_mesh_generator.
GetMesh();
144 std::vector<DimensionalChastePoint<DIM> > mesh_points = p_temp_mesh->GetNodeLocationsAsPoints();
145 std::vector<std::vector<unsigned> > mesh_connectivity = p_temp_mesh->GetConnectivity();
147 units::quantity<unit::length> reference_length = p_temp_mesh->GetReferenceLengthScale();
148 vtkSmartPointer<vtkPoints> p_vtk_points = vtkSmartPointer<vtkPoints>::New();
149 for(
unsigned idx = 0; idx<mesh_connectivity.size(); idx++)
151 c_vector<double, DIM> location0 = mesh_points[mesh_connectivity[idx][0]].GetLocation(reference_length);
152 c_vector<double, DIM> location1 = mesh_points[mesh_connectivity[idx][1]].GetLocation(reference_length);
153 c_vector<double, DIM> location2 = mesh_points[mesh_connectivity[idx][2]].GetLocation(reference_length);
154 double centx = (location0[0] + location1[0] + location2[0])/3.0;
155 double centy = (location0[1] + location1[1] + location2[1])/3.0;
156 p_vtk_points->InsertNextPoint(centx, centy, 0.0);
160 vtkSmartPointer<vtkPolyData> p_sampling_data = vtkSmartPointer<vtkPolyData>::New();
161 p_sampling_data->SetPoints(p_vtk_points);
163 vtkSmartPointer<vtkProbeFilter> p_image_probe = vtkSmartPointer<vtkProbeFilter>::New();
164 #if VTK_MAJOR_VERSION <= 5 165 p_image_probe->SetInput(p_sampling_data);
166 p_image_probe->SetSource(
mpImage);
168 p_image_probe->SetInputData(p_sampling_data);
169 p_image_probe->SetSourceData(
mpImage);
171 p_image_probe->Update();
173 std::vector<DimensionalChastePoint<DIM> > holes;
174 std::vector<DimensionalChastePoint<DIM> > regions;
175 for(
unsigned idx=0; idx<p_image_probe->GetOutput()->GetPointData()->GetScalars()->GetNumberOfTuples(); idx++)
177 if(p_image_probe->GetOutput()->GetPointData()->GetScalars()->GetTuple1(idx)>5)
181 c_vector<double, DIM> loc;
182 loc[0] = p_vtk_points->GetPoint(idx)[0];
183 loc[1] = p_vtk_points->GetPoint(idx)[1];
195 c_vector<double, DIM> loc;
196 loc[0] = p_vtk_points->GetPoint(idx)[0];
197 loc[1] = p_vtk_points->GetPoint(idx)[1];
205 fine_mesh_generator.
SetHoles(holes);
211 fine_mesh_generator.
Update();
212 boost::shared_ptr<DiscreteContinuumMesh<DIM, DIM> > p_fine_mesh = fine_mesh_generator.
GetMesh();
217 EXCEPTION(
"3d image meshing not yet implemented");
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > mMesh
void SetTissueDomain(boost::shared_ptr< Part< DIM > > pTissueDomain)
boost::shared_ptr< Part< DIM > > mpDomain
void SetDomain(boost::shared_ptr< Part< SPACE_DIM > > pDomain)
static boost::shared_ptr< ImageToMesh< DIM > > Create()
void SetInput(vtkSmartPointer< vtkImageData > pImage)
vtkSmartPointer< vtkImageData > mpImage
boost::shared_ptr< DiscreteContinuumMesh< DIM, DIM > > GetMesh()
void SetRegionMarkers(std::vector< DimensionalChastePoint< SPACE_DIM > > regionMarkers)
void SetMaxElementArea(units::quantity< unit::volume > maxElementArea)
units::quantity< unit::volume > mElementSize
boost::shared_ptr< DiscreteContinuumMesh< ELEMENT_DIM, SPACE_DIM > > GetMesh()
void SetHoles(std::vector< DimensionalChastePoint< SPACE_DIM > > holes)
void SetElementSize(units::quantity< unit::volume > elementSize)
void SetInputRaw(vtkImageData *pImage)