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();
109 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
111 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
114 if(strlen(mOrientationArray.c_str())==0)
116 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
119 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
122 mColorArrayList <<
"";
124 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
126 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
129 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
133 mShowGlyph = shouldGlyphBeEnableByDefault();
144 QDomDocument doc = dataNode.ownerDocument();
146 QDomNode meshNode = dataNode;
148 QDomElement colorNode = doc.createElement(
"color");
149 QDomElement subNode = doc.createElement(
"red");
150 subNode.appendChild(doc.createTextNode(
string_cast(mColor.red()).c_str()));
151 colorNode.appendChild(subNode);
152 subNode = doc.createElement(
"green");
153 subNode.appendChild(doc.createTextNode(
string_cast(mColor.green()).c_str()));
154 colorNode.appendChild(subNode);
155 subNode = doc.createElement(
"blue");
156 subNode.appendChild(doc.createTextNode(
string_cast(mColor.blue()).c_str()));
157 colorNode.appendChild(subNode);
158 subNode = doc.createElement(
"alpha");
159 subNode.appendChild(doc.createTextNode(
string_cast(mColor.alpha()).c_str()));
160 colorNode.appendChild(subNode);
161 meshNode.appendChild(colorNode);
163 QDomElement cullingNode = doc.createElement(
"culling");
164 QDomElement elem = cullingNode.toElement();
165 elem.setAttribute(
"backfaceCulling", mBackfaceCulling);
166 elem.setAttribute(
"frontfaceCulling", mFrontfaceCulling);
167 meshNode.appendChild(cullingNode);
169 QDomElement glyphNode = doc.createElement(
"glyph");
170 QDomElement elemGlyph = glyphNode.toElement();
171 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
172 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
173 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
174 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
175 elemGlyph.setAttribute(
"glyphVisSize", mVisSize);
176 meshNode.appendChild(elemGlyph);
187 if (dataNode.isNull())
193 QDomNode colorNode = dataNode.namedItem(
"color");
194 if (!colorNode.isNull())
201 QDomNode node = colorNode.namedItem(
"red");
203 red = node.toElement().text().toInt();
205 node = colorNode.namedItem(
"green");
207 green = node.toElement().text().toInt();
209 node = colorNode.namedItem(
"blue");
211 blue = node.toElement().text().toInt();
213 node = colorNode.namedItem(
"alpha");
215 alpha = node.toElement().text().toInt();
217 mColor = QColor(red, green, blue, alpha);
220 QDomNode cullingNode = dataNode.namedItem(
"culling");
221 if (!cullingNode.isNull())
223 mBackfaceCulling = cullingNode.toElement().attribute(
"backfaceCulling").toInt();
224 mFrontfaceCulling = cullingNode.toElement().attribute(
"frontfaceCulling").toInt();
227 QDomNode glyphNode = dataNode.namedItem(
"glyph");
228 if (!glyphNode.isNull())
230 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
231 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
232 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
233 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
234 mVisSize = glyphNode.toElement().attribute(
"glyphVisSize").toDouble();
253 mBackfaceCulling = backfaceCulling;
259 return mBackfaceCulling;
264 mFrontfaceCulling = frontfaceCulling;
270 return mFrontfaceCulling;
289 bool Mesh::shouldGlyphBeEnableByDefault()
291 if(! mHasGlyph)
return false;
292 if(!mVtkPolyData)
return false;
293 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
294 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
295 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
296 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
304 return mOrientationArray.c_str();
309 mOrientationArray = orientationArray;
320 if(mVisSize==size)
return;
328 return mColorArray.c_str();
333 mColorArray = colorArray;
339 return mGlyphLUT.c_str();
344 mGlyphLUT = glyphLUT;
351 return mOrientationArrayList;
356 return mColorArrayList;
371 if (
similar(transform, Transform3D::Identity()))
380 floatPoints->DeepCopy(points);
381 floatPoints->SetDataTypeToFloat();
382 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
385 p = transform.coord(p);
386 floatPoints->SetPoint(i, p.begin());
388 poly->SetPoints(floatPoints.GetPointer());
398 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
405 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
406 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)