36 #include <vtkCellArray.h>
37 #include <vtkColorSeries.h>
38 #include <vtkPolyData.h>
39 #include <vtkPolyDataWriter.h>
40 #include <vtkPointData.h>
41 #include <QDomDocument>
58 Data(uid, name), mVtkPolyData(
vtkPolyDataPtr::New()), mWireframe(false), mBackfaceCulling(false), mFrontfaceCulling(false),mHasGlyph(false), mOrientationArray(
""), mColorArray(
""),mVisSize(2.0)
60 mColor = QColor(255, 0, 0, 255);
61 mShowGlyph = shouldGlyphBeEnableByDefault();
66 Data(uid, name), mVtkPolyData(polyData), mWireframe(false), mBackfaceCulling(false), mFrontfaceCulling(false),mHasGlyph(false), mOrientationArray(
""), mColorArray(
""),mVisSize(2.0)
68 mColor = QColor(255, 0, 0, 255);
69 mShowGlyph = shouldGlyphBeEnableByDefault();
94 this->
setName(QFileInfo(path).baseName());
102 mVtkPolyData = polyData;
103 mOrientationArrayList.clear();
104 mColorArrayList.clear();
107 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
109 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
112 if(strlen(mOrientationArray.c_str())==0)
114 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
117 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
120 mColorArrayList <<
"";
122 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
124 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
127 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
130 mShowGlyph = shouldGlyphBeEnableByDefault();
141 QDomDocument doc = dataNode.ownerDocument();
143 QDomNode meshNode = dataNode;
145 QDomElement colorNode = doc.createElement(
"color");
146 QDomElement subNode = doc.createElement(
"red");
147 subNode.appendChild(doc.createTextNode(
string_cast(mColor.red()).c_str()));
148 colorNode.appendChild(subNode);
149 subNode = doc.createElement(
"green");
150 subNode.appendChild(doc.createTextNode(
string_cast(mColor.green()).c_str()));
151 colorNode.appendChild(subNode);
152 subNode = doc.createElement(
"blue");
153 subNode.appendChild(doc.createTextNode(
string_cast(mColor.blue()).c_str()));
154 colorNode.appendChild(subNode);
155 subNode = doc.createElement(
"alpha");
156 subNode.appendChild(doc.createTextNode(
string_cast(mColor.alpha()).c_str()));
157 colorNode.appendChild(subNode);
158 meshNode.appendChild(colorNode);
160 QDomElement cullingNode = doc.createElement(
"culling");
161 QDomElement elem = cullingNode.toElement();
162 elem.setAttribute(
"backfaceCulling", mBackfaceCulling);
163 elem.setAttribute(
"frontfaceCulling", mFrontfaceCulling);
164 meshNode.appendChild(cullingNode);
166 QDomElement glyphNode = doc.createElement(
"glyph");
167 QDomElement elemGlyph = glyphNode.toElement();
168 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
169 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
170 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
171 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
172 elemGlyph.setAttribute(
"glyphVisSize", mVisSize);
173 meshNode.appendChild(elemGlyph);
184 if (dataNode.isNull())
190 QDomNode colorNode = dataNode.namedItem(
"color");
191 if (!colorNode.isNull())
198 QDomNode node = colorNode.namedItem(
"red");
200 red = node.toElement().text().toInt();
202 node = colorNode.namedItem(
"green");
204 green = node.toElement().text().toInt();
206 node = colorNode.namedItem(
"blue");
208 blue = node.toElement().text().toInt();
210 node = colorNode.namedItem(
"alpha");
212 alpha = node.toElement().text().toInt();
214 mColor = QColor(red, green, blue, alpha);
217 QDomNode cullingNode = dataNode.namedItem(
"culling");
218 if (!cullingNode.isNull())
220 mBackfaceCulling = cullingNode.toElement().attribute(
"backfaceCulling").toInt();
221 mFrontfaceCulling = cullingNode.toElement().attribute(
"frontfaceCulling").toInt();
224 QDomNode glyphNode = dataNode.namedItem(
"glyph");
225 if (!glyphNode.isNull())
227 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
228 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
229 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
230 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
231 mVisSize = glyphNode.toElement().attribute(
"glyphVisSize").toDouble();
250 mBackfaceCulling = backfaceCulling;
256 return mBackfaceCulling;
261 mFrontfaceCulling = frontfaceCulling;
267 return mFrontfaceCulling;
286 bool Mesh::shouldGlyphBeEnableByDefault()
288 if(! mHasGlyph)
return false;
289 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
290 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
291 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
292 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
300 return mOrientationArray.c_str();
305 mOrientationArray = orientationArray;
316 if(mVisSize==size)
return;
324 return mColorArray.c_str();
329 mColorArray = colorArray;
335 return mGlyphLUT.c_str();
340 mGlyphLUT = glyphLUT;
347 return mOrientationArrayList;
352 return mColorArrayList;
367 if (
similar(transform, Transform3D::Identity()))
376 floatPoints->DeepCopy(points);
377 floatPoints->SetDataTypeToFloat();
378 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
381 p = transform.coord(p);
382 floatPoints->SetPoint(i, p.begin());
384 poly->SetPoints(floatPoints.GetPointer());
394 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
401 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
402 this->
setFilename(QDir(basePath).relativeFilePath(filename));
virtual DoubleBoundingBox3D boundingBox() const
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
vtkPolyDataPtr getTransformedPolyData(Transform3D tranform)
Create a new transformed polydata.
const char * getOrientationArray()
bool isFiberBundle() const
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void setVisSize(double size)
void setName(const QString &name)
virtual vtkPolyDataPtr getVtkPolyData() const
virtual bool load(QString path)
cstring_cast_Placeholder cstring_cast(const T &val)
static MeshPtr create(const QString &uid, const QString &name="")
void setFrontfaceCullingSlot(bool backfaceCulling)
Set frontface culling on/off in mesh visualization.
QStringList getColorArrayList()
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
std::string string_cast(const T &val)
virtual QString getUid() const
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
vtkPolyDataPtr loadVtkPolyData(QString filename)
bool getIsWireframe() const
true=wireframe, false=surface
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void setBackfaceCullingSlot(bool backfaceCulling)
Set backface culling on/off in mesh visualization.
void setVtkPolyData(const vtkPolyDataPtr &polyData)
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
bool getBackfaceCulling()
Get backface culling.
void setOrientationArray(const char *orientationArray)
void setAcquisitionTime(QDateTime time)
vtkSmartPointer< class vtkPolyDataWriter > vtkPolyDataWriterPtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
void setIsWireframe(bool on)
Set rep to wireframe, false means surface.
void setGlyphLUT(const char *glyphLUT)
const char * getGlyphLUT()
virtual void save(const QString &basePath)
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Superclass for all data objects.
void addXml(QDomNode &dataNode)
adds xml information about the image and its variabels
void setShowGlyph(bool val)
Mesh(const QString &uid, const QString &name="")
bool getFrontfaceCulling()
Get frontface culling.
void setColorArray(const char *colorArray)
boost::shared_ptr< class Mesh > MeshPtr
QStringList getOrientationArrayList()
const char * getColorArray()
virtual void setFilename(QString val)
vtkSmartPointer< class vtkPoints > vtkPointsPtr
void setColor(const QColor &color)
Set the color of the mesh.
QColor getColor()
Get the color of the mesh (Values are range 0 - 255)