NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMeshHelpers.cpp
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 #include "cxMeshHelpers.h"
34 
35 #include <QColor>
36 
37 #include <vtkPoints.h>
38 #include <vtkCellArray.h>
39 
40 #include "cxPatientModelService.h"
41 #include "cxMesh.h"
42 #include "cxTypeConversions.h"
43 #include "cxTime.h"
44 
45 namespace cx
46 {
48 {
49  vtkPolyDataPtr retval = vtkPolyDataPtr::New();
50 
51  vtkPointsPtr points = vtkPointsPtr::New();
52  vtkCellArrayPtr lines = vtkCellArrayPtr::New();
53 
54  points->Allocate(transformMap_prMt.size());
55 
56  TimedTransformMap::iterator mapIter = transformMap_prMt.begin();
57  while(mapIter != transformMap_prMt.end())
58  {
59  Vector3D point_t = Vector3D(0,0,0);
60 
61  Transform3D prMt = mapIter->second;
62  Transform3D rMt = rMpr * prMt;
63  Vector3D p = rMt.coord(point_t);
64  points->InsertNextPoint(p.begin());
65 
66  ++mapIter;
67  }
68 
69  lines->Initialize();
70  std::vector<vtkIdType> ids(points->GetNumberOfPoints());
71  for (unsigned i=0; i<ids.size(); ++i)
72  ids[i] = i;
73  lines->InsertNextCell(ids.size(), &(*ids.begin()));
74 
75  retval->SetPoints(points);
76  retval->SetLines(lines);
77  return retval;
78 }
79 
81 {
82  //create polydata from positions
83  Transform3D rMpr = dataManager->get_rMpr();
84  vtkPolyDataPtr centerlinePolydata = polydataFromTransforms(transforms_prMt, rMpr);
85  QString uid = "tool_positions_mesh_%1";
86  QString name = "Tool positions mesh %1";
87  MeshPtr mesh = dataManager->createSpecificData<Mesh>(uid, name);
88  mesh->setVtkPolyData(centerlinePolydata);
89  mesh->setColor(QColor("red"));
90  dataManager->insertData(mesh);
91 }
92 
93 std::map<std::string, std::string> getDisplayFriendlyInfo(MeshPtr mesh)
94 {
95  std::map<std::string, std::string> retval;
96  if(!mesh)
97  return retval;
98 
99  //mesh
100  retval["Filename"] = mesh->getFilename().toStdString();
101  retval["Coordinate system"] = mesh->getCoordinateSystem().toString().toStdString();
102  retval["Name"] = mesh->getName().toStdString();
103  retval["Parent space"] = mesh->getParentSpace().toStdString();
104  retval["Space"] = mesh->getSpace().toStdString();
105  retval["Type"] = mesh->getType().toStdString();
106  retval["Uid"] = mesh->getUid().toStdString();
107  retval["rMd"] = string_cast(mesh->get_rMd());
108  retval["Backface culling"] = string_cast(mesh->getBackfaceCulling());
109  retval["Color"] = mesh->getColor().name().toStdString();
110  retval["Frontface culling"] = string_cast(mesh->getFrontfaceCulling());
111  retval["Is wireframe"] = string_cast(mesh->getIsWireframe());
112  retval["Acquisition time"] = string_cast(mesh->getAcquisitionTime().toString(timestampSecondsFormatNice()));
113  retval["Fiber bundle"] = string_cast(mesh->isFiberBundle());
114 
115  //vtkPolyData
116  float actualMemorySizeKB = (float)mesh->getVtkPolyData()->GetActualMemorySize();
117  retval["Actual memory size"] = string_cast(actualMemorySizeKB/(1024*1024))+" GB, "+string_cast(actualMemorySizeKB/1024)+" MB, "+string_cast(actualMemorySizeKB)+" kB";
118  retval["Points"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPoints());
119  retval["Lines"] = string_cast(mesh->getVtkPolyData()->GetNumberOfLines());
120  retval["Pieces"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPieces());
121  retval["Polys"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPolys());
122  retval["Strips"] = string_cast(mesh->getVtkPolyData()->GetNumberOfStrips());
123  retval["Verts"] = string_cast(mesh->getVtkPolyData()->GetNumberOfVerts());
124 
125  return retval;
126 }
127 
128 }//namespace cx
129 
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
A mesh data set.
Definition: cxMesh.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
QString timestampSecondsFormatNice()
Definition: cxTime.cpp:47
std::string string_cast(const T &val)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:100
vtkPolyDataPtr polydataFromTransforms(TimedTransformMap transformMap_prMt, Transform3D rMpr)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void loadMeshFromToolTransforms(PatientModelServicePtr dataManager, TimedTransformMap transforms_prMt)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
boost::shared_ptr< class Mesh > MeshPtr
std::map< double, Transform3D > TimedTransformMap
vtkSmartPointer< class vtkPoints > vtkPointsPtr