Hide menu
Loading...
Searching...
No Matches
modeling/poly/Program.cs

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.
//
// ****************************************************************************
using cadex;
using System;
using System.Runtime.InteropServices;
namespace poly
{
class Program
{
// For more information see https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
static int Main(string[] args)
{
// Add runtime path to CAD Exchanger libraries (e.g. compiled with Visual Studio 2015)
SetDllDirectory("../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
// Activate the license (aKey must be defined in cadex_license.cs)
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate CAD Exchanger license.");
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();
aPart.AddRepresentation(aPolyWithPPS);
aPart.AddRepresentation(aPolyWithPLS);
aPart.AddRepresentation(aPolyWithITS);
aModel.AddRoot(aPart);
aWriter.Write(aModel, new Base_UTF16String("Poly.cdx"));
return 0;
}
static ModelData_PolyPointSet CreatePolyPointSet()
{
ModelData_PointList aPoints1 = new ModelData_PointList();
ModelData_PointList aPoints2 = new ModelData_PointList();
for (int i = 0; i < 10; ++i)
{
aPoints1.Add(new ModelData_Point(i, 0, 0));
aPoints2.Add(new ModelData_Point(i, 0, i));
}
// It's possible to add as much containers of points to same PolyPointSet as you want
aPPS.Add(aPoints1); // aPPS.NumberOfVertices() == 10
aPPS.Add(aPoints2); // aPPS.NumberOfVertices() == 20
return aPPS;
}
// Create PLS from lists of points: each list builds a new PolyLine
static ModelData_PolyLineSet CreatePolyLineSet()
{
ModelData_PointList aPoints1 = new ModelData_PointList();
ModelData_PointList aPoints2 = new ModelData_PointList();
for (int i = 0; i < 10; ++i)
{
aPoints1.Add(new ModelData_Point(i, 3, i / 2));
aPoints2.Add(new ModelData_Point(i, 0, i % 2));
}
// For each new list of points there will be a new PolyLine
aPLS.AddPolyline(aPoints1); // aPLS.NumberOfPolyLines() == 1
aPLS.AddPolyline(aPoints2); // aPLS.NumberOfPolyLines() == 2
return aPLS;
}
// Creates ITS with full information provided
static ModelData_IndexedTriangleSet CreateITS()
{
ModelData_PointList aCoords = new ModelData_PointList
{
new ModelData_Point ( 1.0, 1.0, 1.0),
new ModelData_Point (-1.0, 1.0, 1.0),
new ModelData_Point (-1.0, -1.0, 1.0),
new ModelData_Point ( 1.0, -1.0, 1.0),
new ModelData_Point ( 1.0, 1.0, -1.0),
new ModelData_Point (-1.0, 1.0, -1.0),
new ModelData_Point (-1.0, -1.0, -1.0),
new ModelData_Point ( 1.0, -1.0, -1.0)
};
ModelData_IntList aVerticesIndices = new ModelData_IntList
{
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
};
ModelData_IntList aCounts = new ModelData_IntList { 4, 4, 4, 4, 4, 4 };
ModelData_VectorfList aNormals = new ModelData_VectorfList
{
new ModelData_Vectorf ( 0f, 0f, 1f),
new ModelData_Vectorf ( 0f, 1f, 0f),
new ModelData_Vectorf (-1f, 0f, 0f),
new ModelData_Vectorf ( 0f, -1f, 0f),
new ModelData_Vectorf ( 1f, 0f, 0f),
new ModelData_Vectorf ( 0f, 0f, -1f),
};
ModelData_IntList aNormalsIndices = new ModelData_IntList
{
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
};
ModelData_ColorList aColors = new ModelData_ColorList
{
new ModelData_Color (255, 0, 0),
new ModelData_Color ( 0, 255, 0),
new ModelData_Color ( 0, 0, 255),
new ModelData_Color (255, 255, 0),
new ModelData_Color ( 0, 255, 255),
new ModelData_Color (255, 255, 255)
};
ModelData_IntList aColorIndices = new ModelData_IntList
{
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, aVerticesIndices, aCounts);
anITS.AddNormals(aNormals, aNormalsIndices, aCounts);
anITS.AddColors(aColors, aColorIndices, aCounts);
return anITS;
}
}
}
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
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
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