22 #include <LbmLib/include/reportHandler/vtkCellPNGReporter.hpp>
23 #include <UtilLib/include/Exception.hpp>
25 #include <vtkSmartPointer.h>
26 #include <vtkPolygon.h>
27 #include <vtkCellArray.h>
28 #include <vtkPolyData.h>
29 #include <vtkDoubleArray.h>
30 #include <vtkStringArray.h>
31 #include <vtkPointData.h>
32 #include <vtkMultiBlockDataSet.h>
33 #include <vtkXMLMultiBlockDataWriter.h>
34 #include <vtkXMLMultiBlockDataReader.h>
36 #include <vtkPolyDataMapper.h>
38 #include <vtkRenderWindow.h>
39 #include <vtkRenderer.h>
40 #include <vtkRenderWindowInteractor.h>
41 #include <vtkTriangleFilter.h>
42 #include <vtkWindowToImageFilter.h>
43 #include <vtkPNGWriter.h>
44 #include <vtkImageCanvasSource2D.h>
45 #include <vtkImageCast.h>
53 namespace reportHandler {
55 std::stringstream filename;
56 filename <<
filename_ <<
"_" << time <<
".png";
58 vtkSmartPointer<vtkPoints> polygonpoints =
59 vtkSmartPointer<vtkPoints>::New();
60 vtkSmartPointer<vtkCellArray> polygons =
61 vtkSmartPointer<vtkCellArray>::New();
62 vtkSmartPointer<vtkPolyData> polygonPolyData =
63 vtkSmartPointer<vtkPolyData>::New();
64 vtkTriangleFilter *tri=
65 vtkTriangleFilter::New();
66 vtkPolyDataMapper *map =
67 vtkPolyDataMapper::New();
68 vtkSmartPointer<vtkActor> actor =
69 vtkSmartPointer<vtkActor>::New();
70 vtkSmartPointer<vtkRenderer> renderer =
71 vtkSmartPointer<vtkRenderer>::New();
72 vtkSmartPointer<vtkRenderWindow> renderWindow =
73 vtkSmartPointer<vtkRenderWindow>::New();
74 std::vector<vtkSmartPointer<vtkPolygon> > polygonvector;
75 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
76 vtkSmartPointer<vtkWindowToImageFilter>::New();
77 vtkSmartPointer<vtkPNGWriter> writer =
78 vtkSmartPointer<vtkPNGWriter>::New();
79 std::map<unsigned int,std::vector<std::shared_ptr<LbmLib::geometry::Connection> > > celldefinition;
80 std::shared_ptr<LbmLib::geometry::Connection> startC =
nullptr;
81 std::shared_ptr<LbmLib::geometry::Connection> tempC =
nullptr;
83 int globalpointcounter = 0;
84 int polygonpointcounter;
85 int polygoncounter = 0;
87 for (
auto it : this->connections_) {
88 celldefinition[(*it).getDomainIdentifier()].push_back(it);
91 for (
auto it : celldefinition) {
92 startC = it.second[0];
94 polygonpointcounter = 0;
95 polygonvector.push_back(vtkSmartPointer<vtkPolygon>::New());
98 polygonpoints->InsertNextPoint(tempC->getGeometryNodes().second->getXPos(),
99 tempC->getGeometryNodes().second->getYPos(),
102 polygonvector.back()->GetPointIds()->InsertId(polygonpointcounter, globalpointcounter);
104 tempC = tempC->getGeometryNodes().second->getConnection<1>();
105 globalpointcounter++;
106 polygonpointcounter++;
107 }
while(tempC != startC);
111 for (
auto k : polygonvector) {
112 polygons->InsertNextCell(k);
115 polygonPolyData->SetPoints(polygonpoints);
116 polygonPolyData->SetPolys(polygons);
118 #if VTK_MAJOR_VERSION <= 5
119 tri->SetInput(polygonPolyData);
120 map->SetInput(tri->GetOutput());
122 tri->SetInputData(polygonPolyData);
123 map->SetInputData(tri->GetOutput());
126 actor->SetMapper(map);
128 renderWindow->SetOffScreenRendering( 1 );
129 renderWindow->AddRenderer(renderer);
132 renderer->AddActor(actor);
133 renderer->SetBackground(0,0,0);
134 renderWindow->Render();
136 windowToImageFilter->SetInput(renderWindow);
137 windowToImageFilter->SetMagnification(3);
139 windowToImageFilter->ReadFrontBufferOff();
140 windowToImageFilter->Update();
142 writer->SetFileName(filename.str().c_str());
143 writer->SetInputConnection(windowToImageFilter->GetOutputPort());
virtual void operator()(unsigned int time) const
operator() Writes the report
const std::string filename_
filename_ Stores the filename of this functor