OOFEM 3.0
Loading...
Searching...
No Matches
CSG.h File Reference
#include <algorithm>
#include <memory>
#include <math.h>
#include <vector>
#include <deque>
#include <map>
#include <assert.h>

Go to the source code of this file.

Classes

struct  Vector
struct  Vertex
struct  Plane
struct  Polygon
struct  Model
struct  CSGNode

Typedefs

typedef CSGNodecsg_function(const CSGNode *a1, const CSGNode *b1)
using Tag = size_t
using SideTag = std::pair<Tag, Tag>

Functions

bool approxequal (double a, double b)
bool operator== (const Vector &a, const Vector &b)
bool operator!= (const Vector &a, const Vector &b)
Vector operator+ (const Vector &a, const Vector &b)
Vector operator- (const Vector &a, const Vector &b)
Vector operator* (const Vector &a, double b)
Vector operator/ (const Vector &a, double b)
double dot (const Vector &a, const Vector &b)
Vector lerp (const Vector &a, const Vector &b, double v)
Vector negate (const Vector &a)
double length (const Vector &a)
double lengthsquared (const Vector &a)
Vector unit (const Vector &a)
Vector cross (const Vector &a, const Vector &b)
Vector operator- (const Vector &a)
int lerp (int a, int b, double v)
bool operator== (const Vertex &a, const Vertex &b)
bool operator!= (const Vertex &a, const Vertex &b)
double interpolate_between (const Vertex &a, const Vertex &b, const Vertex &v)
double distanceToLine (const Vector &point, const Vector &linePoint1, const Vector &linePoint2)
void addMissingVertices (Model &mesh)
void writeSTL (const Model &model, std::string filename)
void writeModelsSTL (const std::vector< Model > &models, std::string filename)
Model csgunion (const Model &a, const Model &b)
Model csgintersection (const Model &a, const Model &b)
Model csgsubtract (const Model &a, const Model &b)
std::vector< Polygoncsgunion (const std::vector< Polygon > &a, const std::vector< Polygon > &b)
std::vector< Polygoncsgintersection (const std::vector< Polygon > &a, const std::vector< Polygon > &b)
std::vector< Polygoncsgsubtract (const std::vector< Polygon > &a, const std::vector< Polygon > &b)
std::vector< Polygoncsgpolygon_cube (const Vector &center={ 0.0, 0.0, 0.0 }, const Vector &dim={ 1.0, 1.0, 1.0 }, const int col=0xFFFFFF)
std::vector< Polygoncsgpolygon_sphere (const Vector &center={ 0.0, 0.0, 0.0 }, double radius=1.0, const int col=0xFFFFFF, int slices=16, int stacks=8)
std::vector< Polygoncsgpolygon_cylinder (const Vector &s={ 0.0, -1.0, 0.0 }, const Vector &e={ 0.0, 1.0, 0.0 }, double radius=1.0, const int col=0xFFFFFF, int slices=16)
std::vector< Polygoncsgfixtjunc (const std::vector< Polygon > &polygons)
Model modelfrompolygons (const std::vector< Polygon > &polygons)
Model csgmodel_cube (const Vector &center={ 0.0, 0.0, 0.0 }, const Vector &dim={ 1.0, 1.0, 1.0 }, const int col=0xFFFFFF)
Model csgmodel_sphere (const Vector &center={ 0.0, 0.0, 0.0 }, double radius=1.0, const int col=0xFFFFFF, int slices=16, int stacks=8)
Model csgmodel_cylinder (const Vector &s={ 0.0, -1.0, 0.0 }, const Vector &e={ 0.0, 1.0, 0.0 }, double radius=1.0, const int col=0xFFFFFF, int slices=16)
Vertex flip (Vertex v)
Vertex interpolate (const Vertex &a, const Vertex &b, double t)
CSGNodecsg_union (const CSGNode *a1, const CSGNode *b1)
CSGNodecsg_subtract (const CSGNode *a1, const CSGNode *b1)
CSGNodecsg_intersect (const CSGNode *a1, const CSGNode *b1)
std::vector< Polygonmodeltopolygons (const Model &model)
std::vector< Polygoncsgjs_operation (const std::vector< Polygon > &apoly, const std::vector< Polygon > &bpoly, csg_function fun)
std::vector< Polygoncsgjs_operation (const Model &a, const Model &b, csg_function fun)
template<class CONTTYPE, class T>
bool contains (CONTTYPE &cont, const T &t)
template<class CONTTYPE, class T>
CONTTYPE::iterator find (CONTTYPE &cont, const T &t)
template<class T, typename... Ks>
std::map< Ks... >::iterator find (std::map< Ks... > &cont, const T &t)
template<typename T>
std::vector< T >::iterator find (std::vector< T > &cont, const T &t)
template<typename T>
void remove (std::vector< T > &cont, const T &t)
template<typename T, typename... Ks>
void remove (std::map< Ks... > &cont, const T &t)
bool operator== (const SideTag &a, const SideTag &b)

Variables

const double csgjs_EPSILON = 0.0001
const int kInvalidPolygonIndex = -1

Typedef Documentation

◆ csg_function

typedef CSGNode * csg_function(const CSGNode *a1, const CSGNode *b1)

Definition at line 951 of file CSG.h.

◆ SideTag

using SideTag = std::pair<Tag, Tag>

Definition at line 1146 of file CSG.h.

◆ Tag

using Tag = size_t

Definition at line 1141 of file CSG.h.

Function Documentation

◆ addMissingVertices()

void addMissingVertices ( Model & mesh)

◆ approxequal()

bool approxequal ( double a,
double b )
inline

Definition at line 43 of file CSG.h.

References csgjs_EPSILON.

Referenced by addMissingVertices(), operator!=(), and operator==().

◆ contains()

template<class CONTTYPE, class T>
bool contains ( CONTTYPE & cont,
const T & t )

◆ cross()

Vector cross ( const Vector & a,
const Vector & b )
inline

◆ csg_intersect()

CSGNode * csg_intersect ( const CSGNode * a1,
const CSGNode * b1 )
inline

◆ csg_subtract()

CSGNode * csg_subtract ( const CSGNode * a1,
const CSGNode * b1 )
inline

◆ csg_union()

CSGNode * csg_union ( const CSGNode * a1,
const CSGNode * b1 )
inline

Definition at line 653 of file CSG.h.

References CSGNode::allpolygons(), CSGNode::build(), CSGNode::clipto(), CSGNode::clone(), and CSGNode::invert().

Referenced by csgunion(), and csgunion().

◆ csgfixtjunc()

std::vector< Polygon > csgfixtjunc ( const std::vector< Polygon > & polygons)

◆ csgintersection() [1/2]

Model csgintersection ( const Model & a,
const Model & b )

Definition at line 1081 of file CSG.h.

References csg_intersect(), csgjs_operation(), and modelfrompolygons().

Referenced by Printer::handleG1Command().

◆ csgintersection() [2/2]

std::vector< Polygon > csgintersection ( const std::vector< Polygon > & a,
const std::vector< Polygon > & b )

Definition at line 1096 of file CSG.h.

References csg_intersect(), and csgjs_operation().

◆ csgjs_operation() [1/2]

std::vector< Polygon > csgjs_operation ( const Model & a,
const Model & b,
csg_function fun )
inline

Definition at line 965 of file CSG.h.

References csgjs_operation(), and modeltopolygons().

◆ csgjs_operation() [2/2]

std::vector< Polygon > csgjs_operation ( const std::vector< Polygon > & apoly,
const std::vector< Polygon > & bpoly,
csg_function fun )

◆ csgmodel_cube()

Model csgmodel_cube ( const Vector & center = { 0.0, 0.0, 0.0 },
const Vector & dim = { 1.0, 1.0, 1.0 },
const int col = 0xFFFFFF )

Definition at line 993 of file CSG.h.

References csgpolygon_cube(), and modelfrompolygons().

◆ csgmodel_cylinder()

Model csgmodel_cylinder ( const Vector & s = { 0.0, -1.0, 0.0 },
const Vector & e = { 0.0, 1.0, 0.0 },
double radius = 1.0,
const int col = 0xFFFFFF,
int slices = 16 )

Definition at line 1070 of file CSG.h.

References csgpolygon_cylinder(), and modelfrompolygons().

◆ csgmodel_sphere()

Model csgmodel_sphere ( const Vector & center = { 0.0, 0.0, 0.0 },
double radius = 1.0,
const int col = 0xFFFFFF,
int slices = 16,
int stacks = 8 )

Definition at line 1030 of file CSG.h.

References csgpolygon_sphere(), and modelfrompolygons().

◆ csgpolygon_cube()

std::vector< Polygon > csgpolygon_cube ( const Vector & center = { 0.0, 0.0, 0.0 },
const Vector & dim = { 1.0, 1.0, 1.0 },
const int col = 0xFFFFFF )

Definition at line 970 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

Referenced by csgmodel_cube().

◆ csgpolygon_cylinder()

std::vector< Polygon > csgpolygon_cylinder ( const Vector & s = { 0.0, -1.0, 0.0 },
const Vector & e = { 0.0, 1.0, 0.0 },
double radius = 1.0,
const int col = 0xFFFFFF,
int slices = 16 )

Definition at line 1036 of file CSG.h.

References cross(), M_PI, unit(), and Vector::y.

Referenced by csgmodel_cylinder().

◆ csgpolygon_sphere()

std::vector< Polygon > csgpolygon_sphere ( const Vector & center = { 0.0, 0.0, 0.0 },
double radius = 1.0,
const int col = 0xFFFFFF,
int slices = 16,
int stacks = 8 )

Definition at line 999 of file CSG.h.

References M_PI.

Referenced by csgmodel_sphere().

◆ csgsubtract() [1/2]

Model csgsubtract ( const Model & a,
const Model & b )

Definition at line 1086 of file CSG.h.

References csg_subtract(), csgjs_operation(), and modelfrompolygons().

◆ csgsubtract() [2/2]

std::vector< Polygon > csgsubtract ( const std::vector< Polygon > & a,
const std::vector< Polygon > & b )

Definition at line 1101 of file CSG.h.

References csg_subtract(), and csgjs_operation().

◆ csgunion() [1/2]

Model csgunion ( const Model & a,
const Model & b )

Definition at line 1076 of file CSG.h.

References csg_union(), csgjs_operation(), and modelfrompolygons().

◆ csgunion() [2/2]

std::vector< Polygon > csgunion ( const std::vector< Polygon > & a,
const std::vector< Polygon > & b )

Definition at line 1091 of file CSG.h.

References csg_union(), and csgjs_operation().

◆ distanceToLine()

double distanceToLine ( const Vector & point,
const Vector & linePoint1,
const Vector & linePoint2 )

Definition at line 238 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

Referenced by addMissingVertices().

◆ dot()

double dot ( const Vector & a,
const Vector & b )
inline

◆ find() [1/3]

template<class CONTTYPE, class T>
CONTTYPE::iterator find ( CONTTYPE & cont,
const T & t )

Referenced by csgfixtjunc(), and remove().

◆ find() [2/3]

template<class T, typename... Ks>
std::map< Ks... >::iterator find ( std::map< Ks... > & cont,
const T & t )

Definition at line 1113 of file CSG.h.

◆ find() [3/3]

template<typename T>
std::vector< T >::iterator find ( std::vector< T > & cont,
const T & t )

Definition at line 1116 of file CSG.h.

◆ flip()

Vertex flip ( Vertex v)
inline

Definition at line 540 of file CSG.h.

References negate(), and Vertex::normal.

◆ interpolate()

Vertex interpolate ( const Vertex & a,
const Vertex & b,
double t )
inline

Definition at line 549 of file CSG.h.

References Vertex::col, lerp(), Vertex::normal, and Vertex::pos.

Referenced by Plane::splitpolygon().

◆ interpolate_between()

double interpolate_between ( const Vertex & a,
const Vertex & b,
const Vertex & v )
inline

Definition at line 134 of file CSG.h.

References dot(), lengthsquared(), and Vertex::pos.

Referenced by addMissingVertices().

◆ length()

◆ lengthsquared()

double lengthsquared ( const Vector & a)
inline

Definition at line 93 of file CSG.h.

References dot().

Referenced by csgfixtjunc(), and interpolate_between().

◆ lerp() [1/2]

Vector lerp ( const Vector & a,
const Vector & b,
double v )
inline

Definition at line 80 of file CSG.h.

Referenced by interpolate().

◆ lerp() [2/2]

int lerp ( int a,
int b,
double v )
inline

Definition at line 112 of file CSG.h.

◆ modelfrompolygons()

Model modelfrompolygons ( const std::vector< Polygon > & polygons)

◆ modeltopolygons()

std::vector< Polygon > modeltopolygons ( const Model & model)
inline

Definition at line 910 of file CSG.h.

References Model::indices, and Model::vertices.

Referenced by csgjs_operation().

◆ negate()

Vector negate ( const Vector & a)
inline

Definition at line 84 of file CSG.h.

Referenced by flip(), Plane::flip(), and Polygon::flip().

◆ operator!=() [1/2]

bool operator!= ( const Vector & a,
const Vector & b )
inline

Definition at line 53 of file CSG.h.

References approxequal(), Vector::x, Vector::y, and Vector::z.

◆ operator!=() [2/2]

bool operator!= ( const Vertex & a,
const Vertex & b )
inline

Definition at line 128 of file CSG.h.

References Vertex::col, Vertex::normal, and Vertex::pos.

◆ operator*()

Vector operator* ( const Vector & a,
double b )
inline

Definition at line 68 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

◆ operator+()

Vector operator+ ( const Vector & a,
const Vector & b )
inline

Definition at line 60 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

◆ operator-() [1/2]

Vector operator- ( const Vector & a)
inline

Definition at line 107 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

◆ operator-() [2/2]

Vector operator- ( const Vector & a,
const Vector & b )
inline

Definition at line 64 of file CSG.h.

References Vector::x, Vector::y, and Vector::z.

◆ operator/()

Vector operator/ ( const Vector & a,
double b )
inline

Definition at line 72 of file CSG.h.

◆ operator==() [1/3]

bool operator== ( const SideTag & a,
const SideTag & b )

Definition at line 1147 of file CSG.h.

◆ operator==() [2/3]

bool operator== ( const Vector & a,
const Vector & b )
inline

Definition at line 48 of file CSG.h.

References approxequal(), Vector::x, Vector::y, and Vector::z.

◆ operator==() [3/3]

bool operator== ( const Vertex & a,
const Vertex & b )
inline

Definition at line 123 of file CSG.h.

References Vertex::col, Vertex::normal, and Vertex::pos.

◆ remove() [1/2]

template<typename T, typename... Ks>
void remove ( std::map< Ks... > & cont,
const T & t )

Definition at line 1131 of file CSG.h.

◆ remove() [2/2]

template<typename T>
void remove ( std::vector< T > & cont,
const T & t )

Definition at line 1122 of file CSG.h.

References find().

Referenced by csgfixtjunc(), and oofem::Graph::merge2vertex().

◆ unit()

Vector unit ( const Vector & a)
inline

Definition at line 98 of file CSG.h.

References length().

Referenced by addMissingVertices(), csgpolygon_cylinder(), Plane::Plane(), writeModelsSTL(), and writeSTL().

◆ writeModelsSTL()

void writeModelsSTL ( const std::vector< Model > & models,
std::string filename )

Definition at line 452 of file CSG.h.

References cross(), Vertex::pos, unit(), Vector::x, Vector::y, and Vector::z.

◆ writeSTL()

void writeSTL ( const Model & model,
std::string filename )

Definition at line 429 of file CSG.h.

References cross(), Model::indices, Vertex::pos, unit(), Model::vertices, Vector::x, Vector::y, and Vector::z.

Variable Documentation

◆ csgjs_EPSILON

const double csgjs_EPSILON = 0.0001

Definition at line 28 of file CSG.h.

Referenced by approxequal(), and Plane::classify().

◆ kInvalidPolygonIndex

const int kInvalidPolygonIndex = -1

Definition at line 1139 of file CSG.h.

Referenced by csgfixtjunc().


This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011