| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| #ifndef BASE_BUILDER3D_H |
| #define BASE_BUILDER3D_H |
|
|
| |
|
|
| #include <sstream> |
| #include <vector> |
| #include <cstdint> |
| #include <Base/Tools3D.h> |
| #ifndef FC_GLOBAL_H |
| # include <FCGlobal.h> |
| #endif |
|
|
| #include "Placement.h" |
|
|
| namespace Base |
| { |
| class Matrix4D; |
|
|
| class BaseExport ColorRGB |
| { |
| public: |
| ColorRGB(); |
| ColorRGB(const ColorRGB&) = default; |
| ColorRGB(ColorRGB&&) = default; |
| explicit ColorRGB(float red, float green, float blue); |
| ~ColorRGB() = default; |
| ColorRGB& operator=(const ColorRGB&) = default; |
| ColorRGB& operator=(ColorRGB&&) = default; |
|
|
| float red() const |
| { |
| return Rgb.red; |
| } |
|
|
| float green() const |
| { |
| return Rgb.green; |
| } |
|
|
| float blue() const |
| { |
| return Rgb.blue; |
| } |
|
|
| private: |
| |
| static float valueInRange(float value); |
| struct |
| { |
| float red; |
| float green; |
| float blue; |
| } Rgb; |
| }; |
|
|
| class BaseExport DrawStyle |
| { |
| public: |
| enum class Style |
| { |
| Filled, |
| Lines, |
| Points, |
| 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 VertexOrdering |
| { |
| public: |
| enum class Ordering |
| { |
| UnknownOrdering, |
| Clockwise, |
| CounterClockwise |
| }; |
|
|
| const char* toString() const; |
|
|
| Ordering ordering = Ordering::UnknownOrdering; |
| }; |
|
|
| class BaseExport ShapeType |
| { |
| public: |
| enum class Type |
| { |
| UnknownShapeType, |
| Convex |
| }; |
|
|
| const char* toString() const; |
|
|
| Type type = Type::UnknownShapeType; |
| }; |
|
|
| class BaseExport BindingElement |
| { |
| public: |
| enum class Binding |
| { |
| Overall = 2, |
| PerPart = 3, |
| PerPartIndexed = 4, |
| PerFace = 5, |
| PerFaceIndexed = 6, |
| PerVertex = 7, |
| PerVertexIndexed = 8, |
| Default = Overall, |
| None = Overall |
| }; |
|
|
| const char* bindingAsString() const; |
| Binding value = Binding::Overall; |
| }; |
|
|
| 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: |
| explicit Triangle(const Base::Vector3f& pt1, const Base::Vector3f& pt2, const Base::Vector3f& pt3) |
| : pt1(pt1) |
| , pt2(pt2) |
| , pt3(pt3) |
| {} |
|
|
| const Base::Vector3f& getPoint1() const |
| { |
| return pt1; |
| } |
|
|
| const Base::Vector3f& getPoint2() const |
| { |
| return pt2; |
| } |
|
|
| const Base::Vector3f& getPoint3() const |
| { |
| return pt3; |
| } |
|
|
| private: |
| Base::Vector3f pt1; |
| Base::Vector3f pt2; |
| Base::Vector3f pt3; |
| }; |
|
|
| class Indentation |
| { |
| int spaces = 0; |
|
|
| public: |
| void increaseIndent() |
| { |
| spaces += 2; |
| } |
| void decreaseIndent() |
| { |
| spaces -= 2; |
| } |
| int count() const |
| { |
| return spaces; |
| } |
| friend std::ostream& operator<<(std::ostream& os, Indentation ind) |
| { |
| for (int i = 0; i < ind.count(); i++) { |
| os << " "; |
| } |
| return os; |
| } |
| }; |
|
|
| class BaseExport InventorOutput |
| { |
| public: |
| explicit InventorOutput(std::ostream& result, Indentation& indent); |
| std::ostream& stream(); |
| std::ostream& write(); |
| std::ostream& write(const char*); |
| std::ostream& write(const std::string&); |
| std::ostream& writeLine(); |
| std::ostream& writeLine(const char*); |
| std::ostream& writeLine(const std::string&); |
| void increaseIndent(); |
| void decreaseIndent(); |
|
|
| private: |
| std::ostream& result; |
| Indentation& indent; |
| }; |
|
|
| class BaseExport NodeItem |
| { |
| public: |
| virtual ~NodeItem() = default; |
| virtual void write(InventorOutput& out) const = 0; |
|
|
| protected: |
| NodeItem() = default; |
| NodeItem(const NodeItem&) = default; |
| NodeItem(NodeItem&&) = default; |
| NodeItem& operator=(const NodeItem&) = default; |
| NodeItem& operator=(NodeItem&&) = default; |
| }; |
|
|
| |
| |
| |
| class BaseExport LabelItem: public NodeItem |
| { |
| public: |
| explicit LabelItem(std::string text); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::string text; |
| }; |
|
|
| |
| |
| |
| class BaseExport InfoItem: public NodeItem |
| { |
| public: |
| explicit InfoItem(std::string text); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::string text; |
| }; |
|
|
| |
| |
| |
| class BaseExport BaseColorItem: public NodeItem |
| { |
| public: |
| explicit BaseColorItem(const ColorRGB& rgb); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| ColorRGB rgb; |
| }; |
|
|
| class BaseExport PointItem: public NodeItem |
| { |
| public: |
| explicit PointItem( |
| const Base::Vector3f& point, |
| DrawStyle drawStyle, |
| const ColorRGB& rgb = ColorRGB {1.0F, 1.0F, 1.0F} |
| ); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| Base::Vector3f point; |
| DrawStyle drawStyle; |
| ColorRGB rgb; |
| }; |
|
|
| class BaseExport LineItem: public NodeItem |
| { |
| public: |
| explicit LineItem( |
| const Base::Line3f& line, |
| DrawStyle drawStyle, |
| const ColorRGB& rgb = ColorRGB {1.0F, 1.0F, 1.0F} |
| ); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| Base::Line3f line; |
| DrawStyle drawStyle; |
| ColorRGB rgb; |
| }; |
|
|
| class BaseExport MultiLineItem: public NodeItem |
| { |
| public: |
| |
| |
| explicit MultiLineItem( |
| std::vector<Vector3f> points, |
| DrawStyle drawStyle, |
| const ColorRGB& rgb = ColorRGB {1.0F, 1.0F, 1.0F} |
| ); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::vector<Vector3f> points; |
| DrawStyle drawStyle; |
| ColorRGB rgb; |
| }; |
|
|
| class BaseExport ArrowItem: public NodeItem |
| { |
| public: |
| explicit ArrowItem( |
| const Base::Line3f& line, |
| DrawStyle drawStyle, |
| const ColorRGB& rgb = ColorRGB {1.0F, 1.0F, 1.0F} |
| ); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| Base::Line3f line; |
| DrawStyle drawStyle; |
| ColorRGB rgb; |
| }; |
|
|
| class BaseExport BoundingBoxItem: public NodeItem |
| { |
| public: |
| explicit BoundingBoxItem( |
| const Vector3f& pt1, |
| const Vector3f& pt2, |
| DrawStyle drawStyle, |
| const ColorRGB& rgb = ColorRGB {1.0F, 1.0F, 1.0F} |
| ); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| Vector3f pt1; |
| Vector3f pt2; |
| DrawStyle drawStyle; |
| ColorRGB rgb; |
| }; |
|
|
| |
| |
| |
| class BaseExport MaterialItem: public NodeItem |
| { |
| public: |
| void setAmbientColor(const std::vector<ColorRGB>& rgb); |
| void setDiffuseColor(const std::vector<ColorRGB>& rgb); |
| void setSpecularColor(const std::vector<ColorRGB>& rgb); |
| void setEmissiveColor(const std::vector<ColorRGB>& rgb); |
| void setShininess(const std::vector<float>& value); |
| void setTransparency(const std::vector<float>& value); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| void beginMaterial(InventorOutput& out) const; |
| void endMaterial(InventorOutput& out) const; |
| void writeAmbientColor(InventorOutput& out) const; |
| void writeDiffuseColor(InventorOutput& out) const; |
| void writeSpecularColor(InventorOutput& out) const; |
| void writeEmissiveColor(InventorOutput& out) const; |
| void writeShininess(InventorOutput& out) const; |
| void writeTransparency(InventorOutput& out) const; |
|
|
| private: |
| std::vector<ColorRGB> ambientColor; |
| std::vector<ColorRGB> diffuseColor; |
| std::vector<ColorRGB> specularColor; |
| std::vector<ColorRGB> emissiveColor; |
| std::vector<float> shininess; |
| std::vector<float> transparency; |
| }; |
|
|
| |
| |
| |
| class BaseExport MaterialBindingItem: public NodeItem |
| { |
| public: |
| MaterialBindingItem() = default; |
| explicit MaterialBindingItem(BindingElement::Binding); |
| void setValue(BindingElement::Binding bind); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| BindingElement value; |
| }; |
|
|
| |
| |
| |
| class BaseExport DrawStyleItem: public NodeItem |
| { |
| public: |
| DrawStyleItem() = default; |
| explicit DrawStyleItem(DrawStyle); |
| void setValue(DrawStyle value); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| DrawStyle style; |
| }; |
|
|
| |
| |
| |
| class BaseExport ShapeHintsItem: public NodeItem |
| { |
| public: |
| explicit ShapeHintsItem(float creaseAngle = 0.0F); |
| void setVertexOrdering(VertexOrdering::Ordering); |
| void setShapeType(ShapeType::Type); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| float creaseAngle = 0.0F; |
| VertexOrdering vertexOrdering; |
| ShapeType shapeType; |
| }; |
|
|
| |
| |
| |
| class BaseExport PolygonOffsetItem: public NodeItem |
| { |
| public: |
| void setValue(PolygonOffset value); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| PolygonOffset offset; |
| }; |
|
|
| |
| |
| |
| class BaseExport Coordinate3Item: public NodeItem |
| { |
| public: |
| explicit Coordinate3Item(std::vector<Vector3f> points); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| void beginPoint(InventorOutput& out) const; |
| void endPoint(InventorOutput& out) const; |
| std::vector<Vector3f> points; |
| }; |
|
|
| |
| |
| |
| class BaseExport PointSetItem: public NodeItem |
| { |
| public: |
| void write(InventorOutput& out) const override; |
| }; |
|
|
| |
| |
| |
| class BaseExport LineSetItem: public NodeItem |
| { |
| public: |
| void write(InventorOutput& out) const override; |
| }; |
|
|
| |
| |
| |
| class BaseExport FaceSetItem: public NodeItem |
| { |
| public: |
| explicit FaceSetItem(std::vector<int>); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::vector<int> indices; |
| }; |
|
|
| |
| |
| |
| class BaseExport IndexedLineSetItem: public NodeItem |
| { |
| public: |
| explicit IndexedLineSetItem(std::vector<int>); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::vector<int> indices; |
| }; |
|
|
| |
| |
| |
| class BaseExport IndexedFaceSetItem: public NodeItem |
| { |
| public: |
| explicit IndexedFaceSetItem(std::vector<int>); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::vector<int> indices; |
| }; |
|
|
| |
| |
| |
| class BaseExport NormalItem: public NodeItem |
| { |
| public: |
| explicit NormalItem(std::vector<Base::Vector3f> vec); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| void beginNormal(InventorOutput& out) const; |
| void endNormal(InventorOutput& out) const; |
| std::vector<Base::Vector3f> vector; |
| }; |
|
|
| |
| |
| |
| class BaseExport NormalBindingItem: public NodeItem |
| { |
| public: |
| NormalBindingItem() = default; |
| void setValue(BindingElement::Binding bind); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| BindingElement value; |
| }; |
|
|
| |
| |
| |
| class BaseExport CylinderItem: public NodeItem |
| { |
| public: |
| void setRadius(float); |
| void setHeight(float); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| float radius = 2.0F; |
| float height = 10.0F; |
| }; |
|
|
| |
| |
| |
| class BaseExport ConeItem: public NodeItem |
| { |
| public: |
| void setBottomRadius(float); |
| void setHeight(float); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| float bottomRadius = 2.0F; |
| float height = 10.0F; |
| }; |
|
|
| |
| |
| |
| class BaseExport SphereItem: public NodeItem |
| { |
| public: |
| void setRadius(float); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| float radius = 2.0F; |
| }; |
|
|
| |
| |
| |
| class BaseExport NurbsSurfaceItem: public NodeItem |
| { |
| public: |
| void setControlPoints(int numU, int numV); |
| void setKnotVector(const std::vector<float>&, const std::vector<float>&); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| int numUControlPoints = 0; |
| int numVControlPoints = 0; |
| std::vector<float> uKnotVector; |
| std::vector<float> vKnotVector; |
| }; |
|
|
| |
| |
| |
| class BaseExport Text2Item: public NodeItem |
| { |
| public: |
| explicit Text2Item(std::string); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| std::string string; |
| }; |
|
|
| |
| |
| |
| class BaseExport TransformItem: public NodeItem |
| { |
| public: |
| explicit TransformItem(const Base::Placement&); |
| explicit TransformItem(const Base::Matrix4D&); |
| void write(InventorOutput& out) const override; |
|
|
| private: |
| Base::Placement placement; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| class BaseExport InventorBuilder |
| { |
| public: |
| |
| |
| |
| |
| explicit InventorBuilder(std::ostream& str); |
| |
| |
| |
| void addHeader(); |
| |
| |
| |
| virtual ~InventorBuilder(); |
| |
| |
| |
| |
| void addNode(const NodeItem&); |
| |
| |
| |
| void beginSeparator(); |
| |
| |
| |
| void endSeparator(); |
|
|
| private: |
| void increaseIndent(); |
| void decreaseIndent(); |
|
|
| public: |
| InventorBuilder(const InventorBuilder&) = delete; |
| InventorBuilder(InventorBuilder&&) = delete; |
| void operator=(const InventorBuilder&) = delete; |
| void operator=(InventorBuilder&&) = delete; |
|
|
| private: |
| std::ostream& result; |
| Indentation indent; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class BaseExport Builder3D |
| { |
| public: |
| Builder3D(); |
| ~Builder3D(); |
|
|
| |
| void clear(); |
|
|
| |
| |
| |
| void saveToLog(); |
| |
| void saveToFile(const char* FileName); |
| |
|
|
| |
| |
| |
| |
| void addNode(const NodeItem&); |
| |
| |
| |
| void beginSeparator(); |
| |
| |
| |
| void endSeparator(); |
|
|
| Builder3D(const Builder3D&) = delete; |
| Builder3D(Builder3D&&) = delete; |
| Builder3D& operator=(const Builder3D&) = delete; |
| Builder3D& operator=(Builder3D&&) = delete; |
|
|
| private: |
| |
| std::stringstream result; |
| InventorBuilder builder; |
| }; |
|
|
| |
| |
| |
| |
| class BaseExport InventorLoader |
| { |
| public: |
| struct Face |
| { |
| Face(int32_t p1, int32_t p2, int32_t p3) |
| : p1(p1) |
| , p2(p2) |
| , p3(p3) |
| {} |
| int32_t p1, p2, p3; |
| }; |
|
|
| explicit InventorLoader(std::istream& inp) |
| : inp(inp) |
| {} |
|
|
| |
| |
| bool read(); |
|
|
| |
| bool isValid() const; |
|
|
| |
| |
| bool isNonIndexed() const |
| { |
| return isnonindexed; |
| } |
|
|
| |
| const std::vector<Vector3f>& getVector() const |
| { |
| return vector; |
| } |
|
|
| |
| const std::vector<Vector3f>& getPoints() const |
| { |
| return points; |
| } |
|
|
| |
| const std::vector<Face>& getFaces() const |
| { |
| return faces; |
| } |
|
|
| private: |
| void readNormals(); |
| void readCoords(); |
| void readIndexedFaceSet(); |
| void readFaceSet(); |
| template<typename T> |
| std::vector<T> readData(const char*) const; |
| std::vector<Vector3f> convert(const std::vector<float>&) const; |
| std::vector<Face> convert(const std::vector<int32_t>&) const; |
| std::vector<Face> convert(const std::vector<std::vector<int32_t>>&) const; |
| static std::vector<std::vector<int32_t>> split(const std::vector<int32_t>&); |
|
|
| private: |
| bool isnonindexed = false; |
| std::vector<Vector3f> vector; |
| std::vector<Vector3f> points; |
| std::vector<Face> faces; |
| std::istream& inp; |
| }; |
|
|
| |
| |
| |
| |
| |
| BaseExport Base::Vector3f stringToVector(std::string); |
|
|
| |
| |
| |
| |
| |
| BaseExport std::string vectorToString(Vector3f); |
|
|
| } |
|
|
| #endif |
|
|