Hide menu
Loading...
Searching...
No Matches
modeling/poly/main.cxx

Refer to the Polygonal Modeling Example.

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include <cadex/Base_String.hxx>
#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData_Color.hxx>
#include <cadex/ModelData_IndexedTriangleSet.hxx>
#include <cadex/ModelData_ModelWriter.hxx>
#include <cadex/ModelData_Point2d.hxx>
#include <cadex/ModelData_PolyLineSet.hxx>
#include <cadex/ModelData_PolyPointSet.hxx>
#include <cadex/ModelData_PolyRepresentation.hxx>
#include <cadex/ModelData_Vector.hxx>
#include <array>
#include <iostream>
#include <vector>
#include "../../cadex_license.cxx"
using namespace std;
using namespace cadex;
// Simply creates PPS
ModelData_PolyPointSet CreatePolyPointSet()
{
vector<ModelData_Point> aPoints1, aPoints2;
for (int i = 0; i < 10; ++i) {
aPoints1.push_back (ModelData_Point (i, 0, 0));
aPoints2.push_back (ModelData_Point (i, 0, i));
}
// It's possible to add as much containers of points to same PolyPointSet as you want.
aPPS.Add (aPoints1.data(), aPoints1.size()); // aPPS.NumberOfVertices() == 10
aPPS.Add (aPoints2.data(), aPoints2.size()); // aPPS.NumberOfVertices() == 20
return aPPS;
}
// Creates PLS from vectors of points: each vector builds a new PolyLine
ModelData_PolyLineSet CreatePolyLineSet()
{
vector<ModelData_Point> aPoints1, aPoints2;
for (int i = 0; i < 10; ++i) {
aPoints1.push_back (ModelData_Point (i, 3, i / 2));
aPoints2.push_back (ModelData_Point (i, 0, i % 2));
}
// For each new vector of points there will be a new PolyLine
aPLS.AddPolyLine (aPoints1.data(), aPoints1.size()); // aPLS.NumberOfPolyLines() == 1
aPLS.AddPolyLine (aPoints2.data(), aPoints2.size()); // aPLS.NumberOfPolyLines() == 2
return aPLS;
}
// Creates ITS with full information provided
{
// Here we create a simple cube
array<ModelData_Point, 8> aCoords = {{
ModelData_Point ( 1., 1., 1.), //top
ModelData_Point (-1., 1., 1.),
ModelData_Point (-1., -1., 1.),
ModelData_Point ( 1., -1., 1.),
ModelData_Point ( 1., 1., -1.), //bot
ModelData_Point (-1., 1., -1.),
ModelData_Point (-1., -1., -1.),
ModelData_Point ( 1., -1., -1.)
}};
array<int, 24> aVerticesIndices = {{
0, 1, 2, 3, // 1
1, 0, 4, 5, // 2
2, 1, 5, 6, // 3
3, 2, 6, 7, // 4
0, 3, 7, 4, // 5
7, 6, 5, 4, // 6
}};
array<int, 6> aCounts = {{4, 4, 4, 4, 4, 4}};
array<ModelData_Vectorf, 6> aNormals = {{
ModelData_Vectorf ( 0.f, 0.f, 1.f), // 1
ModelData_Vectorf ( 0.f, 1.f, 0.f), // 2
ModelData_Vectorf (-1.f, 0.f, 0.f), // 3
ModelData_Vectorf ( 0.f, -1.f, 0.f), // 4
ModelData_Vectorf ( 1.f, 0.f, 0.f), // 5
ModelData_Vectorf ( 0.f, 0.f, -1.f), // 6
}};
array<int, 24> aNormalsIndices = {{
0, 0, 0, 0, // 1
1, 1, 1, 1, // 2
2, 2, 2, 2, // 3
3, 3, 3, 3, // 4
4, 4, 4, 4, // 5
5, 5, 5, 5, // 6
}};
array<ModelData_Color, 6> aColors = {{
ModelData_Color (255, 0, 0 ),
ModelData_Color (0, 255, 0 ),
ModelData_Color (0, 0, 255),
ModelData_Color (255, 255, 0 ),
ModelData_Color (0, 255, 255),
ModelData_Color (255, 255, 255),
}};
array<int, 24> aColorsIndices = {{
0, 0, 0, 0, // 1
1, 1, 1, 1, // 2
2, 2, 2, 2, // 3
3, 3, 3, 3, // 4
4, 4, 4, 4, // 5
5, 5, 5, 5, // 6
}};
anITS.AddCoordinates (aCoords.data(), aCoords.size(), aVerticesIndices.data(), aCounts.data(), aCounts.size());
anITS.AddNormals (aNormals.data(), aNormals.size(), aNormalsIndices.data(), aCounts.data(), aCounts.size());
anITS.AddColors (aColors.data(), aColors.size(), aColorsIndices.data(), aCounts.data(), aCounts.size());
return anITS;
}
int main()
{
auto aKey = LicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cxx)
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate CAD Exchanger license." << endl;
return 1;
}
// Create PolyPointSet and explore it
ModelData_PolyPointSet aPPS = CreatePolyPointSet();
// Create PolyLineSet and explore it
ModelData_PolyLineSet aPLS = CreatePolyLineSet();
// Create IndexedTriangleSet and explore it
ModelData_IndexedTriangleSet anITS = CreateITS();
ModelData_PolyRepresentation aPolyWithPPS (aPPS);
ModelData_PolyRepresentation aPolyWithPLS (aPLS);
ModelData_PolyRepresentation aPolyWithITS (anITS);
aPart.AddRepresentation (aPolyWithPPS);
aPart.AddRepresentation (aPolyWithPLS);
aPart.AddRepresentation (aPolyWithITS);
aModel.AddRoot (aPart);
aWriter.Write (aModel, "Poly.cdx");
return 0;
}
Defines an RGBA color (with alpha channel).
Definition: ModelData_Color.hxx:34
Defines a polygonal shape consisting of triangles.
Definition: ModelData_IndexedTriangleSet.hxx:35
void AddCoordinates(const CoordType theVertices[], size_t theVertexNb)
Adds vertex coordinates.
Definition: ModelData_IndexedTriangleSet.cxx:336
void AddNormals(const NormalType theNormals[], size_t theNormalNb, const IndexType theIndices[], size_t theIndexNb)
Adds vertex normals.
Definition: ModelData_IndexedTriangleSet.cxx:364
void AddColors(const ColorType theColors[], size_t theColorNb, const IndexType theIndices[], size_t theIndexNb)
Adds vertex colors.
Definition: ModelData_IndexedTriangleSet.cxx:382
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
const ModelData_SceneGraphElement & AddRoot(const ModelData_SceneGraphElement &theElement)
Adds new root element into the scene graph.
Definition: ModelData_Model.cxx:830
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33
bool Write(const ModelData_Model &theModel, const Base_UTF16String &theFilePath)
Writes the specified model to the file at the specified path.
Definition: ModelData_ModelWriter.cxx:143
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:35
void AddRepresentation(const ModelData_Representation &theRepresentation)
Adds a representation.
Definition: ModelData_Part.cxx:341
Defines a 3D point.
Definition: ModelData_Point.hxx:295
Defines a polygonal shape consisting of polylines.
Definition: ModelData_PolyLineSet.hxx:31
void AddPolyLine(const CoordType *theVertices, size_t theSize)
Adds a polyline into the set.
Definition: ModelData_PolyLineSet.cxx:108
Defines a polygonal shape consisting of individual points.
Definition: ModelData_PolyPointSet.hxx:31
void Add(const CoordType *thePoints, size_t theSize)
Adds points into a point set.
Definition: ModelData_PolyPointSet.cxx:80
Defines polygonal (faceted or tessellated) representation of part.
Definition: ModelData_PolyRepresentation.hxx:39
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22