Base: start of refactoring of InventorBuilder

This commit is contained in:
wmayer
2022-11-27 16:45:16 +01:00
parent dafe5f11fb
commit f0e22410db
6 changed files with 186 additions and 214 deletions

View File

@@ -70,6 +70,41 @@ float ColorRGB::valueInRange(float value)
return std::clamp(value, valueMinLegal, valueMaxLegal);
}
const char* DrawStyle::styleAsString() const
{
switch (style) {
case Style::Filled:
return "FILLED";
case Style::Lines:
return "LINES";
case Style::Points:
return "POINTS";
case Style::Invisible:
return "INVISIBLE";
}
return "FILLED";
}
std::string DrawStyle::patternAsString() const
{
std::stringstream str;
str << "0x" << std::hex << linePattern;
return str.str();
}
const char* PolygonOffset::styleAsString() const
{
switch (style) {
case Style::Filled:
return "FILLED";
case Style::Lines:
return "LINES";
case Style::Points:
return "POINTS";
}
return "FILLED";
}
/**
* A constructor.
* A more elaborate description of the constructor.
@@ -171,7 +206,6 @@ void Builder3D::addText(const Base::Vector3f& point, const char * text, const Ba
<< "Transform { translation " << point.x << " "<< point.y << " "<< point.z << "} "
<< "Text2 { string \" " << text << "\" " << "} "
<< "} ";
}
void Builder3D::clear ()
@@ -188,8 +222,7 @@ void Builder3D::clear ()
void Builder3D::addSingleLine(const Base::Line3f& line, DrawStyle drawStyle, const ColorRGB& color)
{
char pattern[20];
sprintf(pattern, "0x%x", drawStyle.linePattern);
std::string pattern = drawStyle.patternAsString();
result << "Separator { "
<< "Material { diffuseColor " << color.red() << " "<< color.green() << " "<< color.blue() << "} "
@@ -277,7 +310,7 @@ void Builder3D::addTransformation(const Base::Placement& transform)
{
Base::Vector3d translation = transform.getPosition();
Base::Vector3d rotationaxis;
double angle;
double angle{};
transform.getRotation().getValue(rotationaxis, angle);
result << "Transform {";
result << " translation " << translation.x << " " << translation.y << " " << translation.z;
@@ -377,21 +410,21 @@ void InventorBuilder::addLabel(const char* text)
result << Base::blanks(indent) << "} \n";
}
void InventorBuilder::addBaseColor(float color_r, float color_g, float color_b)
void InventorBuilder::addBaseColor(const ColorRGB& rgb)
{
result << Base::blanks(indent) << "BaseColor { \n";
result << Base::blanks(indent) << " rgb "
<< color_r << " " << color_g << " " << color_b << '\n';
<< rgb.red() << " " << rgb.green() << " " << rgb.blue() << '\n';
result << Base::blanks(indent) << "} \n";
}
void InventorBuilder::addMaterial(float color_r, float color_g, float color_b, float color_a)
void InventorBuilder::addMaterial(const ColorRGB& rgb, float transparency)
{
result << Base::blanks(indent) << "Material { \n";
result << Base::blanks(indent) << " diffuseColor "
<< color_r << " " << color_g << " " << color_b << '\n';
if (color_a > 0)
result << Base::blanks(indent) << " transparency " << color_a << '\n';
<< rgb.red() << " " << rgb.green() << " " << rgb.blue() << '\n';
if (transparency > 0)
result << Base::blanks(indent) << " transparency " << transparency << '\n';
result << Base::blanks(indent) << "} \n";
}
@@ -411,9 +444,9 @@ void InventorBuilder::endMaterial()
result << Base::blanks(indent) << "}\n";
}
void InventorBuilder::addColor(float color_r, float color_g, float color_b)
void InventorBuilder::addColor(const ColorRGB& rgb)
{
result << color_r << " " << color_g << " " << color_b << '\n';
result << rgb.red() << " " << rgb.green() << " " << rgb.blue() << '\n';
}
void InventorBuilder::addMaterialBinding(const char* bind)
@@ -422,30 +455,30 @@ void InventorBuilder::addMaterialBinding(const char* bind)
<< bind << " } \n";
}
void InventorBuilder::addDrawStyle(short pointSize, short lineWidth, unsigned short linePattern, const char* style)
void InventorBuilder::addDrawStyle(DrawStyle drawStyle)
{
result << Base::blanks(indent) << "DrawStyle {\n"
<< Base::blanks(indent) << " style " << style << '\n'
<< Base::blanks(indent) << " pointSize " << pointSize << '\n'
<< Base::blanks(indent) << " lineWidth " << lineWidth << '\n'
<< Base::blanks(indent) << " linePattern " << linePattern << '\n'
<< Base::blanks(indent) << " style " << drawStyle.styleAsString() << '\n'
<< Base::blanks(indent) << " pointSize " << drawStyle.pointSize << '\n'
<< Base::blanks(indent) << " lineWidth " << drawStyle.lineWidth << '\n'
<< Base::blanks(indent) << " linePattern " << drawStyle.linePattern << '\n'
<< Base::blanks(indent) << "}\n";
}
void InventorBuilder::addShapeHints(float crease)
void InventorBuilder::addShapeHints(float creaseAngle)
{
result << Base::blanks(indent) << "ShapeHints {\n"
<< Base::blanks(indent) << " creaseAngle " << crease << '\n'
<< Base::blanks(indent) << " creaseAngle " << creaseAngle << '\n'
<< Base::blanks(indent) << "}\n";
}
void InventorBuilder::addPolygonOffset(float factor, float units, const char* styles, bool on)
void InventorBuilder::addPolygonOffset(PolygonOffset polygonOffset)
{
result << Base::blanks(indent) << "PolygonOffset {\n"
<< Base::blanks(indent) << " factor " << factor << '\n'
<< Base::blanks(indent) << " units " << units << '\n'
<< Base::blanks(indent) << " styles " << styles << '\n'
<< Base::blanks(indent) << " on " << (on ? "TRUE" : "FALSE") << '\n'
<< Base::blanks(indent) << " factor " << polygonOffset.factor << '\n'
<< Base::blanks(indent) << " units " << polygonOffset.units << '\n'
<< Base::blanks(indent) << " styles " << polygonOffset.styleAsString() << '\n'
<< Base::blanks(indent) << " on " << (polygonOffset.on ? "TRUE" : "FALSE") << '\n'
<< Base::blanks(indent) << "}\n";
}
@@ -468,21 +501,16 @@ void InventorBuilder::beginPoints()
}
/// insert a point in a point set
void InventorBuilder::addPoint(float x, float y, float z)
void InventorBuilder::addPoint(const Vector3f& pnt)
{
result << Base::blanks(indent) << x << " " << y << " " << z << ",\n";
result << Base::blanks(indent) << pnt.x << " " << pnt.y << " " << pnt.z << ",\n";
}
/// add a vector to a point set
void InventorBuilder::addPoint(const Vector3f &vec)
void InventorBuilder::addPoints(const std::vector<Vector3f>& points)
{
addPoint(vec.x, vec.y, vec.z);
}
void InventorBuilder::addPoints(const std::vector<Vector3f> &vec)
{
for (std::vector<Vector3f>::const_iterator it = vec.begin(); it != vec.end(); ++it)
addPoint(it->x, it->y, it->z);
for (const auto& pnt : points) {
addPoint(pnt);
}
}
/**
@@ -530,66 +558,53 @@ void InventorBuilder::addLineSet()
* lower leftmost corner.
* @param pos_x,pos_y,pos_z origin of the text
* @param text the text to display.
* @param color_r red part of the text color (0.0 - 1.0).
* @param color_g green part of the text color (0.0 - 1.0).
* @param color_b blue part of the text color (0.0 - 1.0).
* @param color text color.
*/
void InventorBuilder::addText(float pos_x, float pos_y, float pos_z, const char * text, float color_r, float color_g, float color_b)
void InventorBuilder::addText(const Vector3f& pnt, const char * text, const ColorRGB& rgb)
{
result << Base::blanks(indent) << "Separator { \n"
<< Base::blanks(indent) << " Material { diffuseColor "
<< color_r << " "<< color_g << " "<< color_b << "} \n"
<< rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< Base::blanks(indent) << " Transform { translation "
<< pos_x << " "<< pos_y << " "<< pos_z << "} \n"
<< pnt.x << " "<< pnt.y << " "<< pnt.z << "} \n"
<< Base::blanks(indent) << " Text2 { string \" " << text << "\" " << "} \n"
<< Base::blanks(indent) << "}\n";
}
void InventorBuilder::addText(const Vector3f &vec, const char * text, float color_r, float color_g, float color_b)
{
addText(vec.x, vec.y , vec.z,text, color_r,color_g,color_b);
}
//**************************************************************************
// line/arrow handling
void InventorBuilder::addSingleLine(const Vector3f& pt1, const Vector3f& pt2, short lineSize,
float color_r, float color_g, float color_b, unsigned short linePattern)
void InventorBuilder::addSingleLine(const Base::Line3f& line, Base::DrawStyle drawStyle, const ColorRGB& rgb)
{
char lp[20];
sprintf(lp, "0x%x", linePattern);
//char lp[20] = "0x";
//itoa(linePattern, buf, 16);
//strcat(lp, buf);
std::string pattern = drawStyle.patternAsString();
result << " Separator { \n"
<< " Material { diffuseColor " << color_r << " "<< color_g << " "<< color_b << "} \n"
<< " DrawStyle { lineWidth " << lineSize << " linePattern " << lp << " } \n"
<< " Coordinate3 { \n"
<< " point [ "
<< pt1.x << " " << pt1.y << " " << pt1.z << ","
<< pt2.x << " " << pt2.y << " " << pt2.z
<< " ] \n"
<< " } \n"
<< " LineSet { } \n"
<< " } \n";
result << " Separator { \n"
<< " Material { diffuseColor " << rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< " DrawStyle { lineWidth " << drawStyle.lineWidth << " linePattern " << pattern << " } \n"
<< " Coordinate3 { \n"
<< " point [ "
<< line.p1.x << " " << line.p1.y << " " << line.p1.z << ","
<< line.p2.x << " " << line.p2.y << " " << line.p2.z
<< " ] \n"
<< " } \n"
<< " LineSet { } \n"
<< " } \n";
}
void InventorBuilder::addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, short lineSize,
float color_r, float color_g, float color_b, unsigned short /*linePattern*/)
void InventorBuilder::addSingleArrow(const Base::Line3f& line, Base::DrawStyle drawStyle, const ColorRGB& rgb)
{
float l = (pt2 - pt1).Length();
float l = line.Length();
float cl = l / 10.0f;
float cr = cl / 2.0f;
Vector3f dir = pt2 - pt1;
Vector3f dir = line.GetDirection();
dir.Normalize();
dir.Scale(l-cl, l-cl, l-cl);
Vector3f pt2s = pt1 + dir;
Vector3f pt2s = line.p1 + dir;
dir.Normalize();
dir.Scale(l-cl/2.0f, l-cl/2.0f, l-cl/2.0f);
Vector3f cpt = pt1 + dir;
Vector3f cpt = line.p1 + dir;
Vector3f rot = Vector3f(0.0f, 1.0f, 0.0f) % dir;
rot.Normalize();
@@ -597,12 +612,12 @@ void InventorBuilder::addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, s
result << Base::blanks(indent) << "Separator { \n"
<< Base::blanks(indent) << " Material { diffuseColor "
<< color_r << " "<< color_g << " "<< color_b << "} \n"
<< rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< Base::blanks(indent) << " DrawStyle { lineWidth "
<< lineSize << "} \n"
<< drawStyle.lineWidth << "} \n"
<< Base::blanks(indent) << " Coordinate3 { \n"
<< Base::blanks(indent) << " point [ "
<< pt1.x << " " << pt1.y << " " << pt1.z << ","
<< line.p1.x << " " << line.p1.y << " " << line.p1.z << ","
<< pt2s.x << " " << pt2s.y << " " << pt2s.z
<< " ] \n"
<< Base::blanks(indent) << " } \n"
@@ -620,45 +635,31 @@ void InventorBuilder::addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, s
/** Add a line defined by a list of points whereat always a pair (i.e. a point and the following point) builds a line.
* The size of the list must then be even.
*/
void InventorBuilder::addLineSet(const std::vector<Vector3f>& points, short lineSize,
float color_r, float color_g, float color_b, unsigned short linePattern)
void InventorBuilder::addLineSet(const std::vector<Vector3f>& points, DrawStyle drawStyle, const ColorRGB& rgb)
{
char lp[20];
sprintf(lp, "0x%x", linePattern);
std::string pattern = drawStyle.patternAsString();
result << " Separator { \n"
<< " Material { diffuseColor " << color_r << " "<< color_g << " "<< color_b << "} \n"
<< " DrawStyle { lineWidth " << lineSize << " linePattern " << lp << " } \n"
<< " Coordinate3 { \n"
<< " point [ ";
std::vector<Vector3f>::const_iterator it = points.begin();
if ( it != points.end() )
{
result << it->x << " " << it->y << " " << it->z;
for ( ++it ; it != points.end(); ++it )
result << ",\n " << it->x << " " << it->y << " " << it->z;
}
result << " ] \n"
<< " } \n"
<< " LineSet { \n"
<< " numVertices [ ";
/*size_t ct = points.size() / 2;
if ( ct > 0 )
{
result << "2";
for (size_t i=1; i<ct; i++)
result << " Separator { \n"
<< " Material { diffuseColor " << rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< " DrawStyle { lineWidth " << drawStyle.lineWidth << " linePattern " << pattern << " } \n"
<< " Coordinate3 { \n"
<< " point [ ";
std::vector<Vector3f>::const_iterator it = points.begin();
if ( it != points.end() )
{
result << ",";
if (i%16==0)
result << "\n ";
result << "2";
result << it->x << " " << it->y << " " << it->z;
for ( ++it ; it != points.end(); ++it )
result << ",\n " << it->x << " " << it->y << " " << it->z;
}
}*/
result << " -1 ";
result << " ] \n"
<< " } \n"
<< " } \n";
result << " ] \n"
<< " } \n"
<< " LineSet { \n"
<< " numVertices [ ";
result << " -1 ";
result << " ] \n"
<< " } \n"
<< " } \n";
}
//**************************************************************************
@@ -736,23 +737,21 @@ void InventorBuilder::addNormalBinding(const char* binding)
<< Base::blanks(indent) << "}\n";
}
void InventorBuilder::addSingleTriangle(const Vector3f& pt0, const Vector3f& pt1, const Vector3f& pt2,
bool filled, short lineSize, float color_r, float color_g, float color_b)
void InventorBuilder::addSingleTriangle(const Triangle& triangle, DrawStyle drawStyle, const ColorRGB& rgb)
{
std::string fs = "";
if (filled)
{
if (drawStyle.style == DrawStyle::Style::Filled) {
fs = " FaceSet { } ";
}
result << " Separator { \n"
<< " Material { diffuseColor " << color_r << " "<< color_g << " "<< color_b << "} \n"
<< " DrawStyle { lineWidth " << lineSize << "} \n"
<< " Material { diffuseColor " << rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< " DrawStyle { lineWidth " << drawStyle.lineWidth << "} \n"
<< " Coordinate3 { \n"
<< " point [ "
<< pt0.x << " " << pt0.y << " " << pt0.z << ","
<< pt1.x << " " << pt1.y << " " << pt1.z << ","
<< pt2.x << " " << pt2.y << " " << pt2.z
<< triangle.getPoint1().x << " " << triangle.getPoint1().y << " " << triangle.getPoint1().z << ","
<< triangle.getPoint2().x << " " << triangle.getPoint2().y << " " << triangle.getPoint2().z << ","
<< triangle.getPoint3().x << " " << triangle.getPoint3().y << " " << triangle.getPoint3().z
<< "] \n"
<< " } \n"
<< " IndexedLineSet { coordIndex[ 0, 1, 2, 0, -1 ] } \n"
@@ -761,22 +760,20 @@ void InventorBuilder::addSingleTriangle(const Vector3f& pt0, const Vector3f& pt1
}
void InventorBuilder::addSinglePlane(const Vector3f& base, const Vector3f& eX, const Vector3f& eY,
float length, float width, bool filled, short lineSize,
float color_r, float color_g, float color_b)
float length, float width, DrawStyle drawStyle, const ColorRGB& rgb)
{
Vector3f pt0 = base;
Vector3f pt1 = base + length * eX;
Vector3f pt2 = base + length * eX + width * eY;
Vector3f pt3 = base + width * eY;
std::string fs = "";
if (filled)
{
if (drawStyle.style == DrawStyle::Style::Filled) {
fs = " FaceSet { } ";
}
result << " Separator { \n"
<< " Material { diffuseColor " << color_r << " "<< color_g << " "<< color_b << "} \n"
<< " DrawStyle { lineWidth " << lineSize << "} \n"
<< " Material { diffuseColor " << rgb.red() << " "<< rgb.green() << " " << rgb.blue() << "} \n"
<< " DrawStyle { lineWidth " << drawStyle.lineWidth << "} \n"
<< " Coordinate3 { \n"
<< " point [ "
<< pt0.x << " " << pt0.y << " " << pt0.z << ","
@@ -861,8 +858,7 @@ void InventorBuilder::addSphere(float radius)
<< Base::blanks(indent) << "}\n";
}
void InventorBuilder::addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, short lineWidth,
float color_r, float color_g, float color_b)
void InventorBuilder::addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, DrawStyle drawStyle, const ColorRGB& rgb)
{
Base::Vector3f pt[8];
pt[0].Set(pt1.x, pt1.y, pt1.z);
@@ -875,8 +871,8 @@ void InventorBuilder::addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, s
pt[7].Set(pt2.x, pt2.y, pt2.z);
result << " Separator { \n"
<< " Material { diffuseColor " << color_r << " "<< color_g << " "<< color_b << "} \n"
<< " DrawStyle { lineWidth " << lineWidth << "} \n"
<< " Material { diffuseColor " << rgb.red() << " "<< rgb.green() << " "<< rgb.blue() << "} \n"
<< " DrawStyle { lineWidth " << drawStyle.lineWidth << "} \n"
<< " Coordinate3 { \n"
<< " point [ "
<< " " << pt[0].x << " " << pt[0].y << " " << pt[0].z << ",\n"
@@ -900,23 +896,24 @@ void InventorBuilder::addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, s
void InventorBuilder::addTransformation(const Matrix4D& transform)
{
Vector3f cAxis, cBase;
float fAngle = 0.0f, fTranslation = 0.0f;
transform.toAxisAngle(cBase, cAxis,fAngle,fTranslation);
cBase.x = static_cast<float>(transform[0][3]);
cBase.y = static_cast<float>(transform[1][3]);
cBase.z = static_cast<float>(transform[2][3]);
addTransformation(cBase,cAxis,fAngle);
Base::Placement placement;
placement.fromMatrix(transform);
addTransformation(placement);
}
void InventorBuilder::addTransformation(const Vector3f& translation, const Vector3f& rotationaxis, float fAngle)
void InventorBuilder::addTransformation(const Base::Placement& transform)
{
Base::Vector3d translation = transform.getPosition();
Base::Vector3d rotationaxis;
double angle{};
transform.getRotation().getValue(rotationaxis, angle);
result << Base::blanks(indent) << "Transform {\n";
result << Base::blanks(indent) << " translation "
<< translation.x << " " << translation.y << " " << translation.z << '\n';
result << Base::blanks(indent) << " rotation "
<< rotationaxis.x << " " << rotationaxis.y << " " << rotationaxis.z
<< " " << fAngle << '\n';
<< " " << angle << '\n';
result << Base::blanks(indent) << "}" << '\n';
}

View File

@@ -66,24 +66,6 @@ protected:
} Rgb;
};
class BaseExport ColorRGBA : public ColorRGB
{
public:
ColorRGBA() : _alpha {1.0F} {
}
explicit ColorRGBA(float red, float green, float blue, float alpha)
: ColorRGB(red, green, blue)
, _alpha {valueInRange(alpha)} {
}
~ColorRGBA() = default;
float alpha() const {
return _alpha;
}
private:
float _alpha;
};
class BaseExport DrawStyle
{
public:
@@ -94,12 +76,30 @@ public:
Invisible
};
const char* styleAsString() const;
std::string patternAsString() const;
Style style = Style::Filled;
unsigned short pointSize = 2;
unsigned short lineWidth = 2;
unsigned short linePattern = 0xffff;
};
class BaseExport PolygonOffset
{
public:
enum class Style {
Filled,
Lines,
Points
};
const char* styleAsString() const;
float factor = 1.0F;
float units = 1.0F;
Style style = Style::Filled;
bool on = true;
};
class BaseExport Triangle
{
public:
@@ -232,7 +232,7 @@ public:
* This automatically opens a separator node.
* \param str - stream to write the content into
*/
InventorBuilder(std::ostream& str);
explicit InventorBuilder(std::ostream& str);
/*!
* \brief Destruction of an InventorBuilder instance
*/
@@ -265,19 +265,12 @@ public:
//@{
/*!
* \brief Sets a base color node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
*/
void addBaseColor(float color_r,float color_g,float color_b);
void addBaseColor(const ColorRGB& rgb);
/*!
* \brief Sets a material node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
* \param color_a - transparency
*/
void addMaterial(float color_r,float color_g,float color_b,float color_a=0);
void addMaterial(const ColorRGB& rgb, float transparency=0);
/*!
* \brief Starts a material node. The node must be closed with \ref endMaterial
* and the colors must be added with \ref addColor().
@@ -289,11 +282,8 @@ public:
void endMaterial();
/*!
* \brief Adds a color to a material node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
*/
void addColor(float color_r,float color_g,float color_b);
void addColor(const ColorRGB& rgb);
/*!
* \brief Sets a material binding node.
* \param binding - binding of the material. Allowed values are:
@@ -303,36 +293,25 @@ public:
void addMaterialBinding(const char* binding = "OVERALL");
/*!
* \brief Sets a draw style node.
* \param pointSize - the point size
* \param lineWidth - the line width
* \param linePattern - the line pattern
* \param style - the draw style
*/
void addDrawStyle(short pointSize, short lineWidth,
unsigned short linePattern = 0xffff, const char* style="FILLED");
void addDrawStyle(DrawStyle drawStyle);
/*!
* \brief Sets a shape hints node.
* \param crease - the crease angle in radians
*/
void addShapeHints(float crease=0.0f);
void addShapeHints(float creaseAngle=0.0f);
/*!
* \brief Sets a polygon offset node.
* \param factor - Offset multiplication factor.
* \param units - Offset translation multiplication factor.
* \param styles - Can be FILLED, LINES or POINTS.
* \param on - Whether the offset is on or off.
*/
void addPolygonOffset(float factor=1.0f, float units=1.0f, const char* styles="FILLED", bool on=true);
void addPolygonOffset(PolygonOffset polygonOffset);
//@}
/** @name Add coordinates */
//@{
/// add a single point
void addPoint(float x, float y, float z);
/// add a single point
void addPoint(const Vector3f &vec);
void addPoint(const Vector3f& pnt);
/// add a list of points
void addPoints(const std::vector<Vector3f> &vec);
void addPoints(const std::vector<Vector3f>& points);
//@}
/** @name Point set handling */
@@ -357,15 +336,12 @@ public:
/** @name Line/Direction handling */
//@{
/// add a line defined by 2 Vector3D
void addSingleLine(const Vector3f& pt1, const Vector3f& pt2, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add a arrow (directed line) by 2 Vector3D. The arrow shows in direction of point 2.
void addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add a line
void addSingleLine(const Base::Line3f& line, DrawStyle drawStyle, const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
/// add a arrow
void addSingleArrow(const Base::Line3f& line, DrawStyle drawStyle, const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
/// add a line defined by a list of points whereat always a pair (i.e. a point and the following point) builds a line.
void addLineSet(const std::vector<Vector3f>& points, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
void addLineSet(const std::vector<Vector3f>& points, DrawStyle drawStyle, const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
/// add an SoLineSet node
void addLineSet();
//@}
@@ -373,10 +349,9 @@ public:
/** @name Triangle handling */
//@{
/// add a (filled) triangle defined by 3 vectors
void addSingleTriangle(const Vector3f& pt0, const Vector3f& pt1, const Vector3f& pt2, bool filled = true, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addSinglePlane(const Vector3f& base, const Vector3f& eX, const Vector3f& eY, float length, float width, bool filled = true,
short lineSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addSingleTriangle(const Triangle& triangle, DrawStyle drawStyle, const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
void addSinglePlane(const Vector3f& base, const Vector3f& eX, const Vector3f& eY, float length, float width, DrawStyle drawStyle,
const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
void addIndexedFaceSet(const std::vector<int>& indices);
void addFaceSet(const std::vector<int>& vertices);
//@}
@@ -392,24 +367,21 @@ public:
/** @name Bounding Box handling */
//@{
void addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, short lineWidth=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, DrawStyle drawStyle,
const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
//@}
/** @name Transformation */
//@{
/// adds a transformation
void addTransformation(const Matrix4D&);
void addTransformation(const Vector3f& translation, const Vector3f& rotationaxis, float fAngle);
void addTransformation(const Base::Placement&);
//@}
/** @name Text handling */
//@{
/// add a text
void addText(float pos_x, float pos_y , float pos_z,const char * text,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
/// add a text
void addText(const Vector3f &vec,const char * text, float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addText(const Vector3f &vec,const char * text, const ColorRGB& rgb = ColorRGB{1.0F, 1.0F, 1.0F});
//@}
private:

View File

@@ -1172,15 +1172,15 @@ void MeshObject::trimByPlane(const Base::Vector3f& base, const Base::Vector3f& n
// Apply the inverted mesh placement to the plane because the trimming is done
// on the untransformed mesh data
Base::Vector3f baseL, normalL;
Base::Vector3f basePlane, normalPlane;
Base::Placement meshPlacement = getPlacement();
meshPlacement.invert();
meshPlacement.multVec(base, baseL);
meshPlacement.getRotation().multVec(normal, normalL);
meshPlacement.multVec(base, basePlane);
meshPlacement.getRotation().multVec(normal, normalPlane);
MeshCore::MeshFacetGrid meshGrid(this->_kernel);
trim.CheckFacets(meshGrid, baseL, normalL, trimFacets, removeFacets);
trim.TrimFacets(trimFacets, baseL, normalL, triangle);
trim.CheckFacets(meshGrid, basePlane, normalPlane, trimFacets, removeFacets);
trim.TrimFacets(trimFacets, basePlane, normalPlane, triangle);
if (!removeFacets.empty())
this->deleteFacets(removeFacets);
if (!triangle.empty())

View File

@@ -273,8 +273,8 @@ MeshCore::MeshKernel* MeshAlgos::boolean(MeshCore::MeshKernel* pMesh1,
self_intersects = gts_surface_is_self_intersecting (s3);
if (self_intersects != NULL) {
// if (verbose)
// gts_surface_print_stats (self_intersects, stderr);
// gts_surface_write (self_intersects, stdout);
// gts_surface_print_stats (self_intersects, stderr);
// gts_surface_write (self_intersects, stdout);
gts_object_destroy (GTS_OBJECT (self_intersects));
gts_object_destroy (GTS_OBJECT (s1));
gts_object_destroy (GTS_OBJECT (s2));
@@ -350,7 +350,7 @@ GtsSurface* MeshAlgos::createGTSSurface(MeshCore::MeshKernel* Mesh)
// creating the edges and add the face to the surface
gts_surface_add_face (Surf,
gts_face_new (Surf->face_class,
gts_face_new (Surf->face_class,
new_edge (aVertex[p1],aVertex[p2]),
new_edge (aVertex[p2],aVertex[p3]),
new_edge (aVertex[p3],aVertex[p1])));

View File

@@ -1091,7 +1091,7 @@ void TopoShape::exportFaceSet(double dev, double ca,
builder.addShapeHints((float)ca);
if (supportFaceColors) {
App::Color c = colors[index];
builder.addMaterial(c.r, c.g, c.b, c.a);
builder.addMaterial(Base::ColorRGB{c.r, c.g, c.b}, c.a);
}
builder.beginPoints();
@@ -1133,7 +1133,9 @@ void TopoShape::exportLineSet(std::ostream& str) const
vertices.push_back(Base::convertTo<Base::Vector3f>(p));
});
builder.addLineSet(vertices, 2, 0, 0, 0);
Base::DrawStyle drawStyle;
drawStyle.lineWidth = 2.0F;
builder.addLineSet(vertices, drawStyle, Base::ColorRGB{0, 0, 0});
}
}

View File

@@ -25,6 +25,7 @@
#include "Mod/Points/App/Points.h"
#include <Base/Builder3D.h>
#include <Base/Converter.h>
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <boost/math/special_functions/fpclassify.hpp>
@@ -126,7 +127,7 @@ PyObject* PointsPy::writeInventor(PyObject * args)
builder.beginPoints();
PointKernel* kernel = getPointKernelPtr();
for (Points::PointKernel::const_iterator it = kernel->begin(); it != kernel->end(); ++it)
builder.addPoint((float)it->x,(float)it->y,(float)it->z);
builder.addPoint(Base::convertTo<Base::Vector3f>(*it));
builder.endPoints();
builder.addPointSet();
builder.close();