13#include <Poco/DOM/AutoPtr.h>
14#include <Poco/DOM/DOMWriter.h>
15#include <Poco/DOM/Document.h>
16#include <Poco/DOM/Element.h>
17#include <Poco/DOM/Text.h>
19#include <Poco/FileStream.h>
21#include <Poco/XML/XMLWriter.h>
27using Poco::XML::AutoPtr;
28using Poco::XML::Document;
29using Poco::XML::DOMWriter;
30using Poco::XML::Element;
32using Poco::XML::XMLWriter;
37Kernel::Logger
g_log(
"vtkGeometryCacheWriter");
44 : m_doc(new Document()), m_filename(
std::move(filename)) {
71 AutoPtr<Element> pRoot =
m_doc->createElement(
"VTKFile");
72 pRoot->setAttribute(
"type",
"PolyData");
73 pRoot->setAttribute(
"version",
"1.0");
74 pRoot->setAttribute(
"byte_order",
"LittleEndian");
75 m_doc->appendChild(pRoot);
76 pRoot->appendChild(
m_root);
85 std::shared_ptr<GeometryHandler> handle =
obj->getGeometryHandler();
86 if (!(handle->canTriangulate()))
88 std::stringstream buf;
90 int name =
obj->getName();
92 auto noPts = handle->numberOfPoints();
94 auto noTris = handle->numberOfTriangles();
96 AutoPtr<Element> pPiece =
m_doc->createElement(
"Piece");
99 pPiece->setAttribute(
"name", buf.str());
103 pPiece->setAttribute(
"NumberOfPoints", buf.str());
107 pPiece->setAttribute(
"NumberOfPolys", buf.str());
109 AutoPtr<Element> pPoints =
m_doc->createElement(
"Points");
110 AutoPtr<Element> pPtsDataArray =
m_doc->createElement(
"DataArray");
112 pPtsDataArray->setAttribute(
"type",
"Float32");
113 pPtsDataArray->setAttribute(
"NumberOfComponents",
"3");
114 pPtsDataArray->setAttribute(
"format",
"ascii");
117 const auto &points = handle->getTriangleVertices();
119 for (i = 0; i < points.size(); i++) {
120 buf << points[i] <<
" ";
122 AutoPtr<Text> pPointText =
m_doc->createTextNode(buf.str());
123 pPtsDataArray->appendChild(pPointText);
124 pPoints->appendChild(pPtsDataArray);
126 AutoPtr<Element> pFaces =
m_doc->createElement(
"Polys");
127 AutoPtr<Element> pTrisDataArray =
m_doc->createElement(
"DataArray");
129 pTrisDataArray->setAttribute(
"type",
"UInt32");
130 pTrisDataArray->setAttribute(
"Name",
"connectivity");
131 pTrisDataArray->setAttribute(
"format",
"ascii");
134 const auto &faces = handle->getTriangleFaces();
135 for (i = 0; i < faces.size(); i++) {
136 buf << faces[i] <<
" ";
138 AutoPtr<Text> pTrisDataText =
m_doc->createTextNode(buf.str());
139 pTrisDataArray->appendChild(pTrisDataText);
140 pFaces->appendChild(pTrisDataArray);
142 AutoPtr<Element> pTrisOffsetDataArray =
m_doc->createElement(
"DataArray");
144 pTrisOffsetDataArray->setAttribute(
"type",
"UInt32");
145 pTrisOffsetDataArray->setAttribute(
"Name",
"offsets");
146 pTrisOffsetDataArray->setAttribute(
"format",
"ascii");
148 for (i = 1; i < noTris + 1; i++) {
151 AutoPtr<Text> pTrisOffsetDataText =
m_doc->createTextNode(buf.str());
152 pTrisOffsetDataArray->appendChild(pTrisOffsetDataText);
153 pFaces->appendChild(pTrisOffsetDataArray);
156 pPiece->appendChild(pPoints);
157 pPiece->appendChild(pFaces);
160 m_root->appendChild(pPiece);
167 writer.setNewLine(
"\n");
168 writer.setOptions(XMLWriter::PRETTY_PRINT);
172 file.open(
m_filename.c_str(), std::ios::trunc);
173 writer.writeNode(file,
m_doc);
176 g_log.
error(
"Geometry Cache file writing exception");
double obj
the value of the quadratic function
Constructive Solid Geometry object.
~vtkGeometryCacheWriter()
Destructor.
void createVTKFileHeader()
creates VTK XML header <VTKFile type="PolyData" version="1.0" byte_order="LittleEndian"> <PolyData> <...
void write()
Write the XML to a file.
Poco::XML::Element * m_root
The root XML element.
void addObject(CSGObject *obj)
Adds the geometry of the Object to the document.
vtkGeometryCacheWriter(std::string)
Constructor.
std::string m_filename
The file name.
Poco::XML::Document * m_doc
The XML document.
void Init()
Initialises the XML Document with the required vtk XML Headings.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
Mantid::Kernel::Logger g_log("Goniometer")