create mesh segments by face colors
This commit is contained in:
parent
1ed35628ab
commit
361951eac3
|
@ -177,17 +177,38 @@ private:
|
|||
{
|
||||
PyObject *shape;
|
||||
|
||||
static char* kwds_lindeflection[] = {"Shape", "LinearDeflection", "AngularDeflection", NULL};
|
||||
static char* kwds_lindeflection[] = {"Shape", "LinearDeflection", "AngularDeflection",
|
||||
"Segments", "GroupColors", NULL};
|
||||
PyErr_Clear();
|
||||
double lindeflection=0;
|
||||
double angdeflection=0.5;
|
||||
if (PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d|d", kwds_lindeflection,
|
||||
&(Part::TopoShapePy::Type), &shape, &lindeflection, &angdeflection)) {
|
||||
PyObject* segment = Py_False;
|
||||
PyObject* groupColors = 0;
|
||||
if (PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d|dO!O", kwds_lindeflection,
|
||||
&(Part::TopoShapePy::Type), &shape, &lindeflection, &angdeflection,
|
||||
&(PyBool_Type), &segment, &groupColors)) {
|
||||
MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
|
||||
mesher.setMethod(MeshPart::Mesher::Standard);
|
||||
mesher.setDeflection(lindeflection);
|
||||
mesher.setAngularDeflection(angdeflection);
|
||||
mesher.setRegular(true);
|
||||
mesher.setSegments(PyObject_IsTrue(segment) ? true : false);
|
||||
if (groupColors) {
|
||||
Py::Sequence list(groupColors);
|
||||
std::vector<uint32_t> colors;
|
||||
colors.reserve(list.size());
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Py::Tuple t(*it);
|
||||
Py::Float r(t[0]);
|
||||
Py::Float g(t[1]);
|
||||
Py::Float b(t[2]);
|
||||
App::Color c(static_cast<double>(r),
|
||||
static_cast<double>(g),
|
||||
static_cast<double>(b));
|
||||
colors.push_back(c.getPackedValue());
|
||||
}
|
||||
mesher.setColors(colors);
|
||||
}
|
||||
return Py::asObject(new Mesh::MeshPy(mesher.createMesh()));
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,7 @@ Mesher::Mesher(const TopoDS_Shape& s)
|
|||
, minLen(0)
|
||||
, maxLen(0)
|
||||
, regular(false)
|
||||
, segments(false)
|
||||
#if defined (HAVE_NETGEN)
|
||||
, fineness(5)
|
||||
, growthRate(0)
|
||||
|
@ -180,6 +181,13 @@ Mesh::MeshObject* Mesher::createMesh() const
|
|||
#endif
|
||||
}
|
||||
|
||||
std::map<uint32_t, std::vector<std::size_t> > colorMap;
|
||||
for (std::size_t i=0; i<colors.size(); i++) {
|
||||
colorMap[colors[i]].push_back(i);
|
||||
}
|
||||
|
||||
bool createSegm = (colors.size() == aMesh->NbDomains());
|
||||
|
||||
MeshCore::MeshFacetArray faces;
|
||||
faces.reserve(aMesh->NbTriangles());
|
||||
|
||||
|
@ -188,7 +196,7 @@ Mesh::MeshObject* Mesher::createMesh() const
|
|||
Standard_Real x2, y2, z2;
|
||||
Standard_Real x3, y3, z3;
|
||||
|
||||
std::list< std::vector<unsigned long> > meshSegments;
|
||||
std::vector< std::vector<unsigned long> > meshSegments;
|
||||
std::size_t numMeshFaces = 0;
|
||||
StlMesh_MeshExplorer xp(aMesh);
|
||||
for (Standard_Integer nbd=1;nbd<=aMesh->NbDomains();nbd++) {
|
||||
|
@ -244,10 +252,12 @@ Mesh::MeshObject* Mesher::createMesh() const
|
|||
}
|
||||
|
||||
// add a segment for the face
|
||||
std::vector<unsigned long> segment(numDomainFaces);
|
||||
std::generate(segment.begin(), segment.end(), Base::iotaGen<unsigned long>(numMeshFaces));
|
||||
numMeshFaces += numDomainFaces;
|
||||
meshSegments.push_back(segment);
|
||||
if (createSegm || this->segments) {
|
||||
std::vector<unsigned long> segment(numDomainFaces);
|
||||
std::generate(segment.begin(), segment.end(), Base::iotaGen<unsigned long>(numMeshFaces));
|
||||
numMeshFaces += numDomainFaces;
|
||||
meshSegments.push_back(segment);
|
||||
}
|
||||
}
|
||||
|
||||
MeshCore::MeshPointArray verts;
|
||||
|
@ -260,8 +270,21 @@ Mesh::MeshObject* Mesher::createMesh() const
|
|||
|
||||
Mesh::MeshObject* meshdata = new Mesh::MeshObject();
|
||||
meshdata->swap(kernel);
|
||||
for (auto it : meshSegments) {
|
||||
meshdata->addSegment(it);
|
||||
if (createSegm) {
|
||||
for (auto it : colorMap) {
|
||||
Mesh::Segment segm(meshdata, false);
|
||||
for (auto jt : it.second) {
|
||||
segm.addIndices(meshSegments[jt]);
|
||||
}
|
||||
segm.save(true);
|
||||
segm.setName("Group");
|
||||
meshdata->addSegment(segm);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (auto it : meshSegments) {
|
||||
meshdata->addSegment(it);
|
||||
}
|
||||
}
|
||||
return meshdata;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,12 @@ public:
|
|||
{ regular = s; }
|
||||
bool isRegular() const
|
||||
{ return regular; }
|
||||
void setSegments(bool s)
|
||||
{ segments = s; }
|
||||
bool isSegments() const
|
||||
{ return segments; }
|
||||
void setColors(const std::vector<uint32_t>& c)
|
||||
{ colors = c; }
|
||||
//@}
|
||||
|
||||
#if defined (HAVE_NETGEN)
|
||||
|
@ -129,6 +135,7 @@ private:
|
|||
double angularDeflection;
|
||||
double minLen, maxLen;
|
||||
bool regular;
|
||||
bool segments;
|
||||
#if defined (HAVE_NETGEN)
|
||||
int fineness;
|
||||
double growthRate;
|
||||
|
@ -138,6 +145,7 @@ private:
|
|||
bool optimize;
|
||||
bool allowquad;
|
||||
#endif
|
||||
std::vector<uint32_t> colors;
|
||||
struct Vertex;
|
||||
};
|
||||
|
||||
|
|
|
@ -246,16 +246,23 @@ bool Tessellation::accept()
|
|||
QString cmd;
|
||||
if (method == 0) { // Standard
|
||||
double devFace = ui->spinSurfaceDeviation->value().getValue();
|
||||
QString param = QString::fromLatin1("Shape=__doc__.getObject(\"%1\").Shape,LinearDeflection=%2")
|
||||
.arg(shape)
|
||||
.arg(devFace);
|
||||
if (ui->meshShapeColors->isChecked())
|
||||
param += QString::fromLatin1(",Segments=True");
|
||||
if (ui->groupsFaceColors->isChecked())
|
||||
param += QString::fromLatin1(",GroupColors=__doc__.getObject(\"%1\").ViewObject.DiffuseColor")
|
||||
.arg(shape);
|
||||
cmd = QString::fromLatin1(
|
||||
"__doc__=FreeCAD.getDocument(\"%1\")\n"
|
||||
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
|
||||
"__mesh__.Mesh=MeshPart.meshFromShape(Shape=__doc__.getObject(\"%2\").Shape,LinearDeflection=%3)\n"
|
||||
"__mesh__.Label=\"%4 (Meshed)\"\n"
|
||||
"__mesh__.Mesh=MeshPart.meshFromShape(%2)\n"
|
||||
"__mesh__.Label=\"%3 (Meshed)\"\n"
|
||||
"__mesh__.ViewObject.CreaseAngle=25.0\n"
|
||||
"del __doc__, __mesh__\n")
|
||||
.arg(this->document)
|
||||
.arg(shape)
|
||||
.arg(devFace)
|
||||
.arg(param)
|
||||
.arg(label);
|
||||
}
|
||||
else if (method == 1) { // Mefisto
|
||||
|
|
|
@ -60,6 +60,19 @@
|
|||
</property>
|
||||
<widget class="QWidget" name="pageStandard">
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>189</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
|
@ -87,18 +100,19 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="groupsFaceColors">
|
||||
<property name="text">
|
||||
<string>Define segments by face colors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<widget class="QCheckBox" name="meshShapeColors">
|
||||
<property name="text">
|
||||
<string>Apply face colors to mesh</string>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>189</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in New Issue
Block a user