CustusX  22.04-rc5
An IGT application
cxtestVtkPolyDataTree.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "vtkForwardDeclarations.h"
14 
15 #include <vtkCellArray.h>
16 #include <vtkLine.h>
17 #include <vtkPoints.h>
18 #include <vtkPolyData.h>
19 
20 #include "cxTransform3D.h"
21 //#include "cxBranchList.h"
22 
23 namespace cxtest
24 {
25 
43 vtkPolyDataPtr makeDummyCenterLine(int nfork1 = 100, int nfork2 = 100, int nfork3 = 100, int x0 = 0)
44 {
45  vtkSmartPointer<vtkPoints> points =
46  vtkSmartPointer<vtkPoints>::New();
47 
48  //branch 1
49  int n1 = nfork1;
50  int n2 = nfork2;
51  int n3 = nfork3;
52  int i = 0;
53  double stepsize = 0.05;
54  double jaggedsize = 0.001;
55  bool jagged = true;
56  while (i < n1)
57  {
58  double x = x0 + i * stepsize;
59  double y = 0;
60  if(jagged)
61  y += jaggedsize*std::pow(-1, i+1);
62  double z = 0;
63  points->InsertPoint(i, x, y, z);
64  ++i;
65  }
66 
67  //branch2
68  while (i < n1 + n2)
69  {
70  double x = x0 + i * stepsize;
71  double y = (i - n1 + 1)*stepsize;
72  if(jagged)
73  y += jaggedsize*std::pow(-1, i+1);
74  double z = 0;
75  points->InsertPoint(i, x, y, z);
76  ++i;
77  }
78 
79  //branch3
80  while (i < n1 + n2 + n3)
81  {
82  double x = x0 + (i-n2)* stepsize;
83  double y = (i - (n1+n2) + 1)*(-stepsize);
84  if(jagged)
85  y += jaggedsize*std::pow(-1, i+1);
86  double z = 0;
87  points->InsertPoint(i, x, y, z);
88  ++i;
89  }
90 
91 
92  // Create a cell array to store the lines in and add the lines to it
93  vtkSmartPointer<vtkCellArray> lines =
94  vtkSmartPointer<vtkCellArray>::New();
95 
96  //Create lines. For - and / it is easy
97  for (unsigned int i = 0; i < points->GetNumberOfPoints()-n3-1; ++i)
98  {
99  vtkSmartPointer<vtkLine> line =
100  vtkSmartPointer<vtkLine>::New();
101  line->GetPointIds()->SetId(0, i);
102  line->GetPointIds()->SetId(1, i + 1);
103  lines->InsertNextCell(line);
104  }
105 
106  //For \ you must attach it close to the fork point.
107  if(n3 > 0)
108  {
109  i = n1-1;
110 
111  //Create first line of the fork between - and \.
112  vtkSmartPointer<vtkLine> line =
113  vtkSmartPointer<vtkLine>::New();
114  line->GetPointIds()->SetId(0, i);
115  line->GetPointIds()->SetId(1, i + n2 +1);
116  lines->InsertNextCell(line);
117 
118  //create rest of \.
119  for (unsigned int i = points->GetNumberOfPoints() - n3; i < points->GetNumberOfPoints()-1; ++i)
120  {
121  vtkSmartPointer<vtkLine> line =
122  vtkSmartPointer<vtkLine>::New();
123  line->GetPointIds()->SetId(0, i);
124  line->GetPointIds()->SetId(1, i + 1);
125  lines->InsertNextCell(line);
126  }
127  }
128 
129  // Create a polydata to store everything in
130  vtkSmartPointer<vtkPolyData> linesPolyData =
131  vtkSmartPointer<vtkPolyData>::New();
132 
133  // Add the points to the dataset
134  linesPolyData->SetPoints(points);
135 
136  // Add the lines to the dataset
137  linesPolyData->SetLines(lines);
138 
139  return linesPolyData;
140 }
141 }
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
vtkPolyDataPtr makeDummyCenterLine(int nfork1=100, int nfork2=100, int nfork3=100, int x0=0)
makeDummyCenterLine This function makes a vtkPolyDataPtr to a dummy centerline looking like a fork: -...