CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) 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 #include "cxMeshHelpers.h"
13 
14 #include <QColor>
15 
16 #include <vtkPoints.h>
17 #include <vtkCellArray.h>
18 
19 #include "cxPatientModelService.h"
20 #include "cxMesh.h"
21 #include "cxTypeConversions.h"
22 #include "cxTime.h"
23 
24 namespace cx
25 {
27 {
28  vtkPolyDataPtr retval = vtkPolyDataPtr::New();
29 
30  vtkPointsPtr points = vtkPointsPtr::New();
31  vtkCellArrayPtr lines = vtkCellArrayPtr::New();
32 
33  points->Allocate(transformMap_prMt.size());
34 
35  TimedTransformMap::iterator mapIter = transformMap_prMt.begin();
36  while(mapIter != transformMap_prMt.end())
37  {
38  Vector3D point_t = Vector3D(0,0,0);
39 
40  Transform3D prMt = mapIter->second;
41  Transform3D rMt = rMpr * prMt;
42  Vector3D p = rMt.coord(point_t);
43  points->InsertNextPoint(p.begin());
44 
45  ++mapIter;
46  }
47 
48  lines->Initialize();
49  std::vector<vtkIdType> ids(points->GetNumberOfPoints());
50  for (unsigned i=0; i<ids.size(); ++i)
51  ids[i] = i;
52  lines->InsertNextCell(ids.size(), &(*ids.begin()));
53 
54  retval->SetPoints(points);
55  retval->SetLines(lines);
56  return retval;
57 }
58 
60 {
61  //create polydata from positions
62  Transform3D rMpr = dataManager->get_rMpr();
63  vtkPolyDataPtr centerlinePolydata = polydataFromTransforms(transforms_prMt, rMpr);
64  QString uid = "tool_positions_mesh_%1";
65  QString name = "Tool positions mesh %1";
66  MeshPtr mesh = dataManager->createSpecificData<Mesh>(uid, name);
67  mesh->setVtkPolyData(centerlinePolydata);
68  mesh->setColor(QColor("red"));
69  dataManager->insertData(mesh);
70 }
71 
72 std::map<std::string, std::string> getDisplayFriendlyInfo(MeshPtr mesh)
73 {
74  std::map<std::string, std::string> retval;
75  if(!mesh)
76  return retval;
77 
78  //mesh
79  retval["Filename"] = mesh->getFilename().toStdString();
80  retval["Coordinate system"] = mesh->getCoordinateSystem().toString().toStdString();
81  retval["Name"] = mesh->getName().toStdString();
82  retval["Parent space"] = mesh->getParentSpace().toStdString();
83  retval["Space"] = mesh->getSpace().toStdString();
84  retval["Type"] = mesh->getType().toStdString();
85  retval["Uid"] = mesh->getUid().toStdString();
86  retval["rMd"] = matrixAsSingleLineString(mesh->get_rMd());
87  retval["Backface culling"] = string_cast(mesh->getBackfaceCulling());
88  retval["Color"] = mesh->getColor().name().toStdString();
89  retval["Frontface culling"] = string_cast(mesh->getFrontfaceCulling());
90 // retval["Is wireframe"] = string_cast(mesh->getIsWireframe());
91  retval["Acquisition time"] = string_cast(mesh->getAcquisitionTime().toString(timestampSecondsFormatNice()));
92  retval["Fiber bundle"] = string_cast(mesh->isFiberBundle());
93 
94  //vtkPolyData
95  float actualMemorySizeKB = (float)mesh->getVtkPolyData()->GetActualMemorySize();
96  retval["Actual memory size"] = string_cast(actualMemorySizeKB/(1024*1024))+" GB, "+string_cast(actualMemorySizeKB/1024)+" MB, "+string_cast(actualMemorySizeKB)+" kB";
97  retval["Points"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPoints());
98  retval["Lines"] = string_cast(mesh->getVtkPolyData()->GetNumberOfLines());
99  retval["Pieces"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPieces());
100  retval["Polys"] = string_cast(mesh->getVtkPolyData()->GetNumberOfPolys());
101  retval["Strips"] = string_cast(mesh->getVtkPolyData()->GetNumberOfStrips());
102  retval["Verts"] = string_cast(mesh->getVtkPolyData()->GetNumberOfVerts());
103 
104  return retval;
105 }
106 
107 }//namespace cx
108 
std::map< std::string, std::string > getDisplayFriendlyInfo(MeshPtr mesh)
A mesh data set.
Definition: cxMesh.h:45
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
std::string matrixAsSingleLineString(cx::Transform3D transform)
QString timestampSecondsFormatNice()
Definition: cxTime.cpp:26
vtkSmartPointer< vtkPoints > vtkPointsPtr
std::string string_cast(const T &val)
void setVtkPolyData(const vtkPolyDataPtr &polyData)
Definition: cxMesh.cpp:92
vtkPolyDataPtr polydataFromTransforms(TimedTransformMap transformMap_prMt, Transform3D rMpr)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void loadMeshFromToolTransforms(PatientModelServicePtr dataManager, TimedTransformMap transforms_prMt)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
boost::shared_ptr< class Mesh > MeshPtr
std::map< double, Transform3D > TimedTransformMap
Namespace for all CustusX production code.