37 #define _BACKWARD_BACKWARD_WARNING_H 1 38 #include <vtkDoubleArray.h> 39 #include <vtkCellData.h> 40 #include <vtkCellArray.h> 41 #include <vtkPointData.h> 43 #include <vtkXMLPolyDataWriter.h> 44 #include <vtkVersion.h> 46 #include "SmartPointers.hpp" 47 #include "Exception.hpp" 48 #include "PetscTools.hpp" 49 #include "VesselNetworkWriter.hpp" 51 template <
unsigned DIM>
54 mpVtkVesselNetwork(vtkSmartPointer<vtkPolyData>::New()),
55 mIsVtkNetworkUpToDate(false),
57 mReferenceLength(1.e-6 *
unit::metres)
62 template <
unsigned DIM>
68 template <
unsigned DIM>
75 template <
unsigned DIM>
82 template <
unsigned DIM>
88 template <
unsigned DIM>
93 EXCEPTION(
"A vessel network is required for the vtk writer.");
98 EXCEPTION(
"A non zero reference length scale is required for the vtk writer.");
106 std::vector<boost::shared_ptr<Vessel<DIM> > > vessels =
mpVesselNetwork->GetVessels();
107 std::vector<vtkSmartPointer<vtkDoubleArray> > pVesselInfoVector;
108 std::map<std::string, double>::iterator vessel_map_iterator;
109 std::map<std::string, double> vessel_data_map = vessels[0]->GetOutputData();
110 for(vessel_map_iterator = vessel_data_map.begin(); vessel_map_iterator != vessel_data_map.end(); vessel_map_iterator++)
112 vtkSmartPointer<vtkDoubleArray> pVesselInfo = vtkSmartPointer<vtkDoubleArray>::New();
113 pVesselInfo->SetNumberOfComponents(1);
114 pVesselInfo->SetNumberOfTuples(vessels.size());
115 pVesselInfo->SetName((*vessel_map_iterator).first.c_str());
116 pVesselInfoVector.push_back(pVesselInfo);
120 std::vector<boost::shared_ptr<VesselNode<DIM> > > nodes =
mpVesselNetwork->GetNodes();
121 std::vector<vtkSmartPointer<vtkDoubleArray> > pNodeInfoVector;
122 std::map<std::string, double>::iterator vtk_node_map_iterator;
123 std::map<std::string, double> vtk_node_map = vessels[0]->GetStartNode()->GetOutputData();
124 for(vtk_node_map_iterator = vtk_node_map.begin(); vtk_node_map_iterator != vtk_node_map.end(); vtk_node_map_iterator++)
126 vtkSmartPointer<vtkDoubleArray> pNodeInfo = vtkSmartPointer<vtkDoubleArray>::New();
127 pNodeInfo->SetNumberOfComponents(1);
128 pNodeInfo->SetNumberOfTuples(nodes.size());
129 pNodeInfo->SetName((*vtk_node_map_iterator).first.c_str());
130 pNodeInfoVector.push_back(pNodeInfo);
134 vtkSmartPointer<vtkPoints> pPoints= vtkSmartPointer<vtkPoints>::New();
135 vtkSmartPointer<vtkCellArray> pLines = vtkSmartPointer<vtkCellArray>::New();
136 unsigned vessel_index=0;
137 for(
unsigned idx=0; idx<nodes.size(); idx++)
139 nodes[idx]->SetId(idx);
142 pPoints->InsertNextPoint(nodes[idx]->rGetLocation().GetLocation(
mReferenceLength)[0],
147 pPoints->InsertNextPoint(nodes[idx]->rGetLocation().GetLocation(
mReferenceLength)[0],
152 std::map<std::string, double> vtk_node_data = nodes[idx]->GetOutputData();
153 for(
unsigned jdx=0; jdx < pNodeInfoVector.size(); jdx++)
155 std::string key = pNodeInfoVector[jdx]->GetName();
157 if(vtk_node_data.count(key) == 1)
159 pNodeInfoVector[jdx]->SetValue(idx, vtk_node_data[key]);
165 typename std::vector<boost::shared_ptr<Vessel<DIM> > >::iterator it;
166 for(it = vessels.begin(); it < vessels.end(); it++)
168 vtkSmartPointer<vtkLine> pLine = vtkSmartPointer<vtkLine>::New();
169 std::vector<boost::shared_ptr<VesselSegment<DIM> > > segments = (*it)->GetSegments();
170 for(
unsigned i = 0; i < segments.size(); i++)
172 pLine->GetPointIds()->InsertId(i, segments[i]->
GetNode(0)->
GetId());
175 if (i == segments.size() - 1)
177 pLine->GetPointIds()->InsertId(i + 1, segments[i]->
GetNode(1)->
GetId());
180 pLines->InsertNextCell(pLine);
183 std::map<std::string, double> vtk_vessel_data = (*it)->GetOutputData();
184 for(
unsigned idx=0; idx < pVesselInfoVector.size(); idx++)
186 std::string key = pVesselInfoVector[idx]->GetName();
188 if(vtk_vessel_data.count(key) == 1)
190 pVesselInfoVector[idx]->SetValue(vessel_index, vtk_vessel_data[key]);
198 for (
unsigned i = 0; i < pVesselInfoVector.size(); i++)
203 for (
unsigned i = 0; i < pNodeInfoVector.size(); i++)
212 template <
unsigned DIM>
218 template <
unsigned DIM>
223 EXCEPTION(
"No file name set for VesselNetworkWriter");
226 if(PetscTools::AmMaster())
228 vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
231 #if VTK_MAJOR_VERSION <= 5
boost::shared_ptr< VesselNetwork< DIM > > mpVesselNetwork
static boost::shared_ptr< VesselNetworkWriter< DIM > > Create()
void SetVesselNetwork(boost::shared_ptr< VesselNetwork< DIM > > pNetwork)
void SetReferenceLengthScale(units::quantity< unit::length > rReferenceLength)
bool mIsVtkNetworkUpToDate
vtkSmartPointer< vtkPolyData > mpVtkVesselNetwork
void SetFileName(const std::string &rFileName)
virtual unsigned GetId() const
boost::shared_ptr< VesselNode< DIM > > GetNode(unsigned index)
units::quantity< unit::length > mReferenceLength
vtkSmartPointer< vtkPolyData > GetOutput()