Fraxinus  17.12-rc1
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "vtkForwardDeclarations.h"
35 
36 #include <vtkCellArray.h>
37 #include <vtkLine.h>
38 #include <vtkPoints.h>
39 #include <vtkPolyData.h>
40 
41 #include "cxTransform3D.h"
42 //#include "cxBranchList.h"
43 
44 namespace cxtest
45 {
46 
64 vtkPolyDataPtr makeDummyCenterLine(int nfork1 = 100, int nfork2 = 100, int nfork3 = 100, int x0 = 0)
65 {
66  vtkSmartPointer<vtkPoints> points =
67  vtkSmartPointer<vtkPoints>::New();
68 
69  //branch 1
70  int n1 = nfork1;
71  int n2 = nfork2;
72  int n3 = nfork3;
73  int i = 0;
74  double stepsize = 0.05;
75  double jaggedsize = 0.001;
76  bool jagged = true;
77  while (i < n1)
78  {
79  double x = x0 + i * stepsize;
80  double y = 0;
81  if(jagged)
82  y += jaggedsize*std::pow(-1, i+1);
83  double z = 0;
84  points->InsertPoint(i, x, y, z);
85  ++i;
86  }
87 
88  //branch2
89  while (i < n1 + n2)
90  {
91  double x = x0 + i * stepsize;
92  double y = (i - n1 + 1)*stepsize;
93  if(jagged)
94  y += jaggedsize*std::pow(-1, i+1);
95  double z = 0;
96  points->InsertPoint(i, x, y, z);
97  ++i;
98  }
99 
100  //branch3
101  while (i < n1 + n2 + n3)
102  {
103  double x = x0 + (i-n2)* stepsize;
104  double y = (i - (n1+n2) + 1)*(-stepsize);
105  if(jagged)
106  y += jaggedsize*std::pow(-1, i+1);
107  double z = 0;
108  points->InsertPoint(i, x, y, z);
109  ++i;
110  }
111 
112 
113  // Create a cell array to store the lines in and add the lines to it
114  vtkSmartPointer<vtkCellArray> lines =
115  vtkSmartPointer<vtkCellArray>::New();
116 
117  //Create lines. For - and / it is easy
118  for (unsigned int i = 0; i < points->GetNumberOfPoints()-n3-1; ++i)
119  {
120  vtkSmartPointer<vtkLine> line =
121  vtkSmartPointer<vtkLine>::New();
122  line->GetPointIds()->SetId(0, i);
123  line->GetPointIds()->SetId(1, i + 1);
124  lines->InsertNextCell(line);
125  }
126 
127  //For \ you must attach it close to the fork point.
128  if(n3 > 0)
129  {
130  i = n1-1;
131 
132  //Create first line of the fork between - and \.
133  vtkSmartPointer<vtkLine> line =
134  vtkSmartPointer<vtkLine>::New();
135  line->GetPointIds()->SetId(0, i);
136  line->GetPointIds()->SetId(1, i + n2 +1);
137  lines->InsertNextCell(line);
138 
139  //create rest of \.
140  for (unsigned int i = points->GetNumberOfPoints() - n3; i < points->GetNumberOfPoints()-1; ++i)
141  {
142  vtkSmartPointer<vtkLine> line =
143  vtkSmartPointer<vtkLine>::New();
144  line->GetPointIds()->SetId(0, i);
145  line->GetPointIds()->SetId(1, i + 1);
146  lines->InsertNextCell(line);
147  }
148  }
149 
150  // Create a polydata to store everything in
151  vtkSmartPointer<vtkPolyData> linesPolyData =
152  vtkSmartPointer<vtkPolyData>::New();
153 
154  // Add the points to the dataset
155  linesPolyData->SetPoints(points);
156 
157  // Add the lines to the dataset
158  linesPolyData->SetLines(lines);
159 
160  return linesPolyData;
161 }
162 }
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: -...