36 #include "NetworkToSurface.hpp" 37 #include "NetworkToImage.hpp" 38 #include <vtkMarchingSquares.h> 39 #include <vtkMarchingCubes.h> 40 #include <vtkCleanPolyData.h> 41 #include <vtkStripper.h> 42 #include <vtkSplineFilter.h> 43 #include <vtkTriangleFilter.h> 44 #include <vtkTransform.h> 45 #include <vtkClipPolyData.h> 46 #include <vtkPolyData.h> 47 #include <vtkIdList.h> 49 #include <vtkCellArray.h> 51 #include <vtkVersion.h> 52 #include <vtkProbeFilter.h> 53 #include <vtkPolyDataNormals.h> 54 #include <vtkWindowedSincPolyDataFilter.h> 58 #include "UblasCustomFunctions.hpp" 59 #include "UblasIncludes.hpp" 60 #include "UnitCollection.hpp" 62 template<
unsigned DIM>
65 mSamplingGridSpacing(2.0 * 1.e-6 *
unit::metres),
66 mSplineResamplingLength(10.0 * 1.e-6 *
unit::metres),
69 mReferenceLength(
BaseUnits::Instance()->GetReferenceLengthScale())
74 template<
unsigned DIM>
81 template<
unsigned DIM>
87 template<
unsigned DIM>
93 template<
unsigned DIM>
99 template<
unsigned DIM>
105 template<
unsigned DIM>
111 template<
unsigned DIM>
117 template<
unsigned DIM>
126 p_net_to_image->SetPaddingFactors(0.1, 0.1, 0.0);
127 p_net_to_image->SetImageDimension(2);
128 p_net_to_image->Update();
129 mpImage = p_net_to_image->GetOutput();
132 vtkSmartPointer<vtkMarchingSquares> p_squares = vtkSmartPointer<vtkMarchingSquares>::New();
133 #if VTK_MAJOR_VERSION <= 5 136 p_squares->SetInputData(
mpImage);
138 p_squares->SetValue(0, 1);
141 vtkSmartPointer<vtkCleanPolyData> p_cleaner = vtkSmartPointer<vtkCleanPolyData>::New();
142 p_cleaner->SetInputConnection(p_squares->GetOutputPort());
144 vtkSmartPointer<vtkStripper> p_stripper = vtkSmartPointer<vtkStripper>::New();
145 p_stripper->SetInputConnection(p_cleaner->GetOutputPort());
148 vtkSmartPointer<vtkSplineFilter> p_spline= vtkSmartPointer<vtkSplineFilter>::New();
150 p_spline->SetSubdivideToLength();
151 p_spline->SetInputConnection(p_stripper->GetOutputPort());
153 vtkSmartPointer<vtkTriangleFilter> p_triangle = vtkSmartPointer<vtkTriangleFilter>::New();
154 p_triangle->SetInputConnection(p_spline->GetOutputPort());
155 p_triangle->Update();
157 vtkSmartPointer<vtkPolyData> p_cleaned = p_triangle->GetOutput();
160 std::vector<boost::shared_ptr<VesselNode<DIM> > > nodes =
mpNetwork->GetNodes();
161 c_vector<double, 3> box_axis = unit_vector<double>(3,0);
163 for(
unsigned idx=0; idx< nodes.size(); idx++)
165 if(nodes[idx]->GetFlowProperties()->IsInputNode() or nodes[idx]->GetFlowProperties()->IsOutputNode())
168 vtkSmartPointer<vtkBox> p_box = vtkSmartPointer<vtkBox>::New();
169 p_box->SetBounds(-1.1*radius, 0.0, -1.1*radius, 1.1*radius, - 1.1*radius, 1.1*radius);
171 c_vector<double, 3> loc;
176 c_vector<double, 3> tangent;
177 tangent[0]= nodes[idx]->GetSegment(0)->GetOppositeNode(nodes[idx])->rGetLocation().GetLocation(
mReferenceLength)[0] - loc[0];
178 tangent[1]= nodes[idx]->GetSegment(0)->GetOppositeNode(nodes[idx])->rGetLocation().GetLocation(
mReferenceLength)[1] - loc[1];
180 tangent /=norm_2(tangent);
182 double rotation_angle = std::acos(inner_prod(box_axis, tangent))*(180.0/M_PI);
183 c_vector<double, 3> rotation_axis = VectorProduct(box_axis, tangent);
185 vtkSmartPointer<vtkTransform> p_tranform = vtkSmartPointer<vtkTransform>::New();
186 if (std::abs(inner_prod(box_axis, tangent)) < 1.0 - 1.e-6)
188 p_tranform->RotateWXYZ(-rotation_angle, rotation_axis[0], rotation_axis[1], rotation_axis[2]);
192 p_tranform->RotateWXYZ(-rotation_angle, 0.0, 0.0, 1.0);
194 p_tranform->Translate(-loc[0],-loc[1], -loc[2]);
195 p_box->SetTransform(p_tranform);
197 vtkSmartPointer<vtkClipPolyData> p_clipper = vtkSmartPointer<vtkClipPolyData>::New();
198 #if VTK_MAJOR_VERSION <= 5 199 p_clipper->SetInput(p_cleaned);
201 p_clipper->SetInputData(p_cleaned);
203 p_clipper->SetClipFunction(p_box);
207 std::vector<unsigned> edge_ids;
208 vtkSmartPointer<vtkIdList> p_cell_list = vtkSmartPointer<vtkIdList>::New();
209 for (
unsigned idx =0; idx< p_clipper->GetOutput()->GetNumberOfPoints(); idx++)
211 p_clipper->GetOutput()->GetPointCells(idx, p_cell_list);
212 if(p_cell_list->GetNumberOfIds()==1)
214 edge_ids.push_back(idx);
218 vtkSmartPointer<vtkLine> p_line = vtkSmartPointer<vtkLine>::New();
219 p_line->GetPointIds()->SetId(0, edge_ids[0]);
220 p_line->GetPointIds()->SetId(1, edge_ids[1]);
221 p_clipper->GetOutput()->GetLines()->InsertNextCell(p_line);
223 p_cleaned->DeepCopy(p_clipper->GetOutput());
234 p_net_to_image->SetPaddingFactors(0.1, 0.1, 0.1);
235 p_net_to_image->SetImageDimension(3);
236 p_net_to_image->Update();
237 mpImage = p_net_to_image->GetOutput();
240 vtkSmartPointer<vtkMarchingCubes> p_cubes = vtkSmartPointer<vtkMarchingCubes>::New();
241 #if VTK_MAJOR_VERSION <= 5 244 p_cubes->SetInputData(
mpImage);
246 p_cubes->SetValue(0, 1);
248 vtkSmartPointer<vtkCleanPolyData> p_cleaner = vtkSmartPointer<vtkCleanPolyData>::New();
249 p_cleaner->SetInputConnection(p_cubes->GetOutputPort());
251 vtkSmartPointer<vtkWindowedSincPolyDataFilter> p_smoother = vtkSmartPointer<vtkWindowedSincPolyDataFilter>::New();
252 p_smoother->SetInputConnection(p_cleaner->GetOutputPort());
253 p_smoother->SetNumberOfIterations(500.0);
254 p_smoother->BoundarySmoothingOn();
255 p_smoother->FeatureEdgeSmoothingOn();
256 p_smoother->SetFeatureAngle(30.0);
257 p_smoother->SetPassBand(0.03);
258 p_smoother->NonManifoldSmoothingOn();
259 p_smoother->NormalizeCoordinatesOn();
260 p_smoother->Update();
262 vtkSmartPointer<vtkPolyData> p_cleaned = p_smoother->GetOutput();
265 std::vector<boost::shared_ptr<VesselNode<DIM> > > nodes =
mpNetwork->GetNodes();
266 c_vector<double, 3> box_axis = unit_vector<double>(3,0);
267 for(
unsigned idx=0; idx< nodes.size(); idx++)
269 if(nodes[idx]->GetFlowProperties()->IsInputNode() or nodes[idx]->GetFlowProperties()->IsOutputNode())
271 double radius = nodes[idx]->GetRadius()/nodes[idx]->GetReferenceLengthScale();
272 vtkSmartPointer<vtkBox> p_box = vtkSmartPointer<vtkBox>::New();
274 p_box->SetBounds(-1.1*radius, 0.0, -1.1*radius, 1.1*radius, - 1.1*radius, 1.1*radius);
276 c_vector<double, 3> loc = nodes[idx]->rGetLocation().GetLocation(
mReferenceLength);
277 c_vector<double, 3> tangent;
278 tangent = nodes[idx]->GetSegment(0)->GetOppositeNode(nodes[idx])->rGetLocation().GetLocation(
mReferenceLength) - loc;
279 tangent /=norm_2(tangent);
281 double rotation_angle = std::acos(inner_prod(box_axis, tangent))*(180.0/M_PI);
282 c_vector<double, 3> rotation_axis = VectorProduct(box_axis, tangent);
284 vtkSmartPointer<vtkTransform> p_tranform = vtkSmartPointer<vtkTransform>::New();
285 if (std::abs(inner_prod(box_axis, tangent)) < 1.0 - 1.e-6)
287 p_tranform->RotateWXYZ(-rotation_angle, rotation_axis[0], rotation_axis[1], rotation_axis[2]);
291 p_tranform->RotateWXYZ(-rotation_angle, 0.0, 0.0, 1.0);
293 p_tranform->Translate(-loc[0],-loc[1], -loc[2]);
294 p_box->SetTransform(p_tranform);
296 vtkSmartPointer<vtkClipPolyData> p_clipper = vtkSmartPointer<vtkClipPolyData>::New();
297 #if VTK_MAJOR_VERSION <= 5 298 p_clipper->SetInput(p_cleaned);
300 p_clipper->SetInputData(p_cleaned);
302 p_clipper->SetClipFunction(p_box);
304 p_cleaned->DeepCopy(p_clipper->GetOutput());
315 vtkSmartPointer<vtkPolyDataNormals> p_normals = vtkSmartPointer<vtkPolyDataNormals>::New();
317 #if VTK_MAJOR_VERSION <= 5 318 p_normals->SetInput(p_cleaned);
320 p_normals->SetInputData(p_cleaned);
323 p_normals->AutoOrientNormalsOn();
324 p_normals->SplittingOff();
325 p_normals->ConsistencyOn();
vtkSmartPointer< vtkImageData > mpImage
units::quantity< unit::length > mReferenceLength
units::quantity< unit::length > mSamplingGridSpacing
vtkSmartPointer< vtkImageData > GetSamplingImage()
units::quantity< unit::length > mSplineResamplingLength
vtkSmartPointer< vtkPolyData > mpSurface
void SetResamplingSplineSize(units::quantity< unit::length > splineResampleSize)
void SetResamplingGridSize(units::quantity< unit::length > sampleGridSize)
boost::shared_ptr< VesselNetwork< DIM > > mpNetwork
vtkSmartPointer< vtkPolyData > GetSurface()
static boost::shared_ptr< NetworkToSurface< DIM > > Create()
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pNetwork)
static boost::shared_ptr< NetworkToImage< DIM > > Create()