2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Anything relating to plane polygons and triangles, and (generally, non-
|
|
|
|
// planar) meshes thereof.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-04-23 07:29:19 +00:00
|
|
|
|
2018-07-12 18:48:51 +00:00
|
|
|
#ifndef SOLVESPACE_POLYGON_H
|
|
|
|
#define SOLVESPACE_POLYGON_H
|
2008-04-23 07:29:19 +00:00
|
|
|
|
2009-07-07 08:21:59 +00:00
|
|
|
class SPointList;
|
2008-04-25 07:04:09 +00:00
|
|
|
class SPolygon;
|
2008-06-21 10:18:20 +00:00
|
|
|
class SContour;
|
2008-05-22 10:28:28 +00:00
|
|
|
class SMesh;
|
2008-05-24 10:34:06 +00:00
|
|
|
class SBsp3;
|
2016-03-14 16:14:24 +00:00
|
|
|
class SOutlineList;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
enum class EarType : uint32_t {
|
|
|
|
UNKNOWN = 0,
|
|
|
|
NOT_EAR = 1,
|
|
|
|
EAR = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class BspClass : uint32_t {
|
|
|
|
POS = 100,
|
|
|
|
NEG = 101,
|
|
|
|
COPLANAR = 200
|
|
|
|
};
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
enum class EdgeKind : uint32_t {
|
|
|
|
NAKED_OR_SELF_INTER = 100,
|
|
|
|
SELF_INTER = 200,
|
|
|
|
TURNING = 300,
|
|
|
|
EMPHASIZED = 400,
|
|
|
|
SHARP = 500,
|
|
|
|
};
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SEdge {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-04-25 07:04:09 +00:00
|
|
|
int tag;
|
2009-01-25 11:52:29 +00:00
|
|
|
int auxA, auxB;
|
2008-04-24 06:22:16 +00:00
|
|
|
Vector a, b;
|
2008-05-30 08:01:19 +00:00
|
|
|
|
|
|
|
static SEdge From(Vector a, Vector b);
|
2016-05-21 05:18:00 +00:00
|
|
|
bool EdgeCrosses(Vector a, Vector b, Vector *pi=NULL, SPointList *spl=NULL) const;
|
2008-04-24 06:22:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SEdgeList {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SEdge> l;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2016-07-21 20:27:53 +00:00
|
|
|
void AddEdge(Vector a, Vector b, int auxA=0, int auxB=0, int tag=0);
|
2016-05-21 05:18:00 +00:00
|
|
|
bool AssemblePolygon(SPolygon *dest, SEdge *errorAt, bool keepDir=false) const;
|
2008-06-21 10:18:20 +00:00
|
|
|
bool AssembleContour(Vector first, Vector last, SContour *dest,
|
2016-05-21 05:18:00 +00:00
|
|
|
SEdge *errorAt, bool keepDir) const;
|
2009-07-07 08:21:59 +00:00
|
|
|
int AnyEdgeCrossings(Vector a, Vector b,
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector *pi=NULL, SPointList *spl=NULL) const;
|
|
|
|
bool ContainsEdgeFrom(const SEdgeList *sel) const;
|
|
|
|
bool ContainsEdge(const SEdge *se) const;
|
2019-05-13 14:34:22 +00:00
|
|
|
void CullExtraneousEdges(bool both=true);
|
2009-04-08 04:54:07 +00:00
|
|
|
void MergeCollinearSegments(Vector a, Vector b);
|
2008-04-25 07:04:09 +00:00
|
|
|
};
|
|
|
|
|
2009-11-09 11:51:38 +00:00
|
|
|
// A kd-tree element needs to go on a side of a node if it's when KDTREE_EPS
|
|
|
|
// of the boundary. So increasing this number never breaks anything, but may
|
|
|
|
// result in more duplicated elements. So it's conservative to be sloppy here.
|
|
|
|
#define KDTREE_EPS (20*LENGTH_EPS)
|
|
|
|
|
|
|
|
class SEdgeLl {
|
|
|
|
public:
|
|
|
|
SEdge *se;
|
|
|
|
SEdgeLl *next;
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
static SEdgeLl *Alloc();
|
2009-11-09 11:51:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SKdNodeEdges {
|
|
|
|
public:
|
|
|
|
int which; // whether c is x, y, or z
|
|
|
|
double c;
|
|
|
|
SKdNodeEdges *gt;
|
|
|
|
SKdNodeEdges *lt;
|
|
|
|
|
|
|
|
SEdgeLl *edges;
|
|
|
|
|
|
|
|
static SKdNodeEdges *From(SEdgeList *sel);
|
|
|
|
static SKdNodeEdges *From(SEdgeLl *sell);
|
2016-05-05 05:54:05 +00:00
|
|
|
static SKdNodeEdges *Alloc();
|
2009-11-09 11:51:38 +00:00
|
|
|
int AnyEdgeCrossings(Vector a, Vector b, int cnt,
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector *pi=NULL, SPointList *spl=NULL) const;
|
2009-11-09 11:51:38 +00:00
|
|
|
};
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
class SPoint {
|
|
|
|
public:
|
|
|
|
int tag;
|
2009-01-21 05:04:38 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
EarType ear;
|
2009-01-21 05:04:38 +00:00
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
Vector p;
|
2009-06-21 09:02:36 +00:00
|
|
|
Vector auxv;
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2009-06-19 07:56:33 +00:00
|
|
|
class SPointList {
|
|
|
|
public:
|
|
|
|
List<SPoint> l;
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2016-05-21 05:18:00 +00:00
|
|
|
bool ContainsPoint(Vector pt) const;
|
|
|
|
int IndexForPoint(Vector pt) const;
|
2009-06-27 05:53:56 +00:00
|
|
|
void IncrementTagFor(Vector pt);
|
2009-06-19 07:56:33 +00:00
|
|
|
void Add(Vector pt);
|
|
|
|
};
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
class SContour {
|
|
|
|
public:
|
2009-01-19 03:33:15 +00:00
|
|
|
int tag;
|
2009-01-21 05:04:38 +00:00
|
|
|
int timesEnclosed;
|
2009-01-22 10:02:46 +00:00
|
|
|
Vector xminPt;
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SPoint> l;
|
2008-05-02 10:54:22 +00:00
|
|
|
|
2008-06-21 10:18:20 +00:00
|
|
|
void AddPoint(Vector p);
|
2016-05-21 05:18:00 +00:00
|
|
|
void MakeEdgesInto(SEdgeList *el) const;
|
2016-05-05 05:54:05 +00:00
|
|
|
void Reverse();
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector ComputeNormal() const;
|
|
|
|
double SignedAreaProjdToNormal(Vector n) const;
|
|
|
|
bool IsClockwiseProjdToNormal(Vector n) const;
|
|
|
|
bool ContainsPointProjdToNormal(Vector n, Vector p) const;
|
|
|
|
void OffsetInto(SContour *dest, double r) const;
|
|
|
|
void CopyInto(SContour *dest) const;
|
2016-05-05 05:54:05 +00:00
|
|
|
void FindPointWithMinX();
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector AnyEdgeMidpoint() const;
|
2009-01-21 05:04:38 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
bool IsEar(int bp, double scaledEps) const;
|
2009-01-21 05:04:38 +00:00
|
|
|
bool BridgeToContour(SContour *sc, SEdgeList *el, List<Vector> *vl);
|
2009-08-21 04:58:28 +00:00
|
|
|
void ClipEarInto(SMesh *m, int bp, double scaledEps);
|
2009-02-27 14:05:08 +00:00
|
|
|
void UvTriangulateInto(SMesh *m, SSurface *srf);
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-06-26 07:28:29 +00:00
|
|
|
typedef struct {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t face;
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor color;
|
2008-06-26 07:28:29 +00:00
|
|
|
} STriMeta;
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
class SPolygon {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<SContour> l;
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector normal;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2016-07-31 10:35:11 +00:00
|
|
|
Vector ComputeNormal() const;
|
2016-05-05 05:54:05 +00:00
|
|
|
void AddEmptyContour();
|
2019-09-11 18:48:27 +00:00
|
|
|
size_t WindingNumberForPoint(Vector p) const;
|
2016-05-21 05:18:00 +00:00
|
|
|
double SignedArea() const;
|
|
|
|
bool ContainsPoint(Vector p) const;
|
|
|
|
void MakeEdgesInto(SEdgeList *el) const;
|
2016-05-05 05:54:05 +00:00
|
|
|
void FixContourDirections();
|
|
|
|
void Clear();
|
2016-05-21 05:18:00 +00:00
|
|
|
bool SelfIntersecting(Vector *intersectsAt) const;
|
|
|
|
bool IsEmpty() const;
|
|
|
|
Vector AnyPoint() const;
|
|
|
|
void OffsetInto(SPolygon *dest, double r) const;
|
2009-02-27 14:05:08 +00:00
|
|
|
void UvTriangulateInto(SMesh *m, SSurface *srf);
|
2009-05-08 08:33:04 +00:00
|
|
|
void UvGridTriangulateInto(SMesh *m, SSurface *srf);
|
2016-07-31 10:35:11 +00:00
|
|
|
void TriangulateInto(SMesh *m) const;
|
|
|
|
void InverseTransformInto(SPolygon *sp, Vector u, Vector v, Vector n) const;
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class STriangle {
|
|
|
|
public:
|
2008-05-30 06:09:41 +00:00
|
|
|
int tag;
|
|
|
|
STriMeta meta;
|
2016-06-25 07:00:49 +00:00
|
|
|
|
|
|
|
union {
|
|
|
|
struct { Vector a, b, c; };
|
|
|
|
Vector vertices[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct { Vector an, bn, cn; };
|
|
|
|
Vector normals[3];
|
|
|
|
};
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2008-05-30 06:09:41 +00:00
|
|
|
static STriangle From(STriMeta meta, Vector a, Vector b, Vector c);
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector Normal() const;
|
2016-05-05 05:54:05 +00:00
|
|
|
void FlipNormal();
|
2016-05-21 05:18:00 +00:00
|
|
|
double MinAltitude() const;
|
|
|
|
bool ContainsPoint(Vector p) const;
|
|
|
|
bool ContainsPointProjd(Vector n, Vector p) const;
|
2016-07-31 10:35:11 +00:00
|
|
|
STriangle Transform(Vector o, Vector u, Vector v) const;
|
2016-11-19 09:21:11 +00:00
|
|
|
bool Raytrace(const Vector &rayPoint, const Vector &rayDir,
|
|
|
|
double *t, Vector *inters) const;
|
2017-01-17 16:57:27 +00:00
|
|
|
double SignedVolume() const;
|
2019-09-11 10:30:48 +00:00
|
|
|
double Area() const;
|
2017-05-22 14:40:25 +00:00
|
|
|
bool IsDegenerate() const;
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SBsp2 {
|
2008-05-22 10:28:28 +00:00
|
|
|
public:
|
2008-05-24 10:34:06 +00:00
|
|
|
Vector np; // normal to the plane
|
|
|
|
|
|
|
|
Vector no; // outer normal to the edge
|
|
|
|
double d;
|
2008-05-21 03:58:14 +00:00
|
|
|
SEdge edge;
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-22 10:28:28 +00:00
|
|
|
SBsp2 *pos;
|
|
|
|
SBsp2 *neg;
|
|
|
|
|
|
|
|
SBsp2 *more;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void InsertTriangleHow(BspClass how, STriangle *tr, SMesh *m, SBsp3 *bsp3);
|
2008-05-24 23:10:00 +00:00
|
|
|
void InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3);
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector IntersectionWith(Vector a, Vector b) const;
|
2016-03-25 14:16:58 +00:00
|
|
|
void InsertEdge(SEdge *nedge, Vector nnp, Vector out);
|
2016-05-21 05:18:00 +00:00
|
|
|
static SBsp2 *InsertOrCreateEdge(SBsp2 *where, SEdge *nedge,
|
|
|
|
Vector nnp, Vector out);
|
2016-05-05 05:54:05 +00:00
|
|
|
static SBsp2 *Alloc();
|
2008-04-24 06:22:16 +00:00
|
|
|
};
|
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class SBsp3 {
|
2008-04-23 07:29:19 +00:00
|
|
|
public:
|
2008-05-23 10:05:07 +00:00
|
|
|
Vector n;
|
|
|
|
double d;
|
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
STriangle tri;
|
|
|
|
SBsp3 *pos;
|
|
|
|
SBsp3 *neg;
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
SBsp3 *more;
|
|
|
|
|
|
|
|
SBsp2 *edges;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
static SBsp3 *Alloc();
|
2016-07-21 20:27:53 +00:00
|
|
|
static SBsp3 *FromMesh(const SMesh *m);
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector IntersectionWith(Vector a, Vector b) const;
|
2008-05-23 10:05:07 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void InsertHow(BspClass how, STriangle *str, SMesh *instead);
|
2016-03-25 14:16:58 +00:00
|
|
|
void Insert(STriangle *str, SMesh *instead);
|
|
|
|
static SBsp3 *InsertOrCreate(SBsp3 *where, STriangle *str, SMesh *instead);
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2016-04-30 11:54:59 +00:00
|
|
|
void InsertConvexHow(BspClass how, STriMeta meta, Vector *vertex, size_t n,
|
2008-05-30 06:09:41 +00:00
|
|
|
SMesh *instead);
|
2016-04-30 11:54:59 +00:00
|
|
|
SBsp3 *InsertConvex(STriMeta meta, Vector *vertex, size_t n, SMesh *instead);
|
2008-05-24 23:10:00 +00:00
|
|
|
|
|
|
|
void InsertInPlane(bool pos2, STriangle *tr, SMesh *m);
|
2008-05-24 10:34:06 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
void GenerateInPaintOrder(SMesh *m) const;
|
2008-05-21 03:58:14 +00:00
|
|
|
};
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-05-21 03:58:14 +00:00
|
|
|
class SMesh {
|
|
|
|
public:
|
2009-01-13 06:56:05 +00:00
|
|
|
List<STriangle> l;
|
2008-05-22 10:28:28 +00:00
|
|
|
|
2008-05-24 23:10:00 +00:00
|
|
|
bool flipNormal;
|
|
|
|
bool keepCoplanar;
|
|
|
|
bool atLeastOneDiscarded;
|
2015-03-26 10:30:12 +00:00
|
|
|
bool isTransparent;
|
2008-05-24 23:10:00 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void Clear();
|
2016-05-21 05:18:00 +00:00
|
|
|
void AddTriangle(const STriangle *st);
|
2008-05-30 06:09:41 +00:00
|
|
|
void AddTriangle(STriMeta meta, Vector a, Vector b, Vector c);
|
2016-05-21 05:18:00 +00:00
|
|
|
void AddTriangle(STriMeta meta, Vector n,
|
|
|
|
Vector a, Vector b, Vector c);
|
|
|
|
void DoBounding(Vector v, Vector *vmax, Vector *vmin) const;
|
|
|
|
void GetBounding(Vector *vmax, Vector *vmin) const;
|
2008-05-24 23:10:00 +00:00
|
|
|
|
2008-05-26 03:39:45 +00:00
|
|
|
void Simplify(int start);
|
|
|
|
|
2008-05-24 23:10:00 +00:00
|
|
|
void AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3);
|
2009-05-24 11:37:07 +00:00
|
|
|
void MakeFromUnionOf(SMesh *a, SMesh *b);
|
|
|
|
void MakeFromDifferenceOf(SMesh *a, SMesh *b);
|
|
|
|
|
|
|
|
void MakeFromCopyOf(SMesh *a);
|
2016-05-21 05:18:00 +00:00
|
|
|
void MakeFromTransformationOf(SMesh *a, Vector trans,
|
|
|
|
Quaternion q, double scale);
|
2009-05-24 11:37:07 +00:00
|
|
|
void MakeFromAssemblyOf(SMesh *a, SMesh *b);
|
|
|
|
|
2009-05-28 07:07:54 +00:00
|
|
|
void MakeEdgesInPlaneInto(SEdgeList *sel, Vector n, double d);
|
2016-06-26 06:39:27 +00:00
|
|
|
void MakeOutlinesInto(SOutlineList *sol, EdgeKind type);
|
2009-05-28 07:07:54 +00:00
|
|
|
|
2016-12-05 03:11:34 +00:00
|
|
|
void PrecomputeTransparency();
|
2017-02-04 10:47:39 +00:00
|
|
|
void RemoveDegenerateTriangles();
|
2019-09-11 10:28:15 +00:00
|
|
|
double CalculateVolume() const;
|
2019-09-11 10:30:48 +00:00
|
|
|
double CalculateSurfaceArea(const std::vector<uint32_t> &faces) const;
|
2016-12-05 03:11:34 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
bool IsEmpty() const;
|
2009-05-24 11:37:07 +00:00
|
|
|
void RemapFaces(Group *g, int remap);
|
2008-06-02 03:31:37 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
uint32_t FirstIntersectionWith(Point2d mp) const;
|
2017-01-17 16:57:27 +00:00
|
|
|
|
|
|
|
Vector GetCenterOfMass() const;
|
2008-04-23 07:29:19 +00:00
|
|
|
};
|
|
|
|
|
2008-05-27 09:52:36 +00:00
|
|
|
// A linked list of triangles
|
|
|
|
class STriangleLl {
|
|
|
|
public:
|
2008-06-30 09:34:03 +00:00
|
|
|
STriangle *tri;
|
2008-05-27 09:52:36 +00:00
|
|
|
|
|
|
|
STriangleLl *next;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
static STriangleLl *Alloc();
|
2008-05-27 09:52:36 +00:00
|
|
|
};
|
|
|
|
|
2016-03-14 16:14:24 +00:00
|
|
|
class SOutline {
|
|
|
|
public:
|
|
|
|
int tag;
|
|
|
|
Vector a, b, nl, nr;
|
2016-05-24 02:26:52 +00:00
|
|
|
|
|
|
|
bool IsVisible(Vector projDir) const;
|
2016-03-14 16:14:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SOutlineList {
|
|
|
|
public:
|
|
|
|
List<SOutline> l;
|
|
|
|
|
|
|
|
void Clear();
|
2016-06-26 06:39:27 +00:00
|
|
|
void AddEdge(Vector a, Vector b, Vector nl, Vector nr, int tag = 0);
|
|
|
|
void ListTaggedInto(SEdgeList *el, int auxA = 0, int auxB = 0);
|
2016-03-14 16:14:24 +00:00
|
|
|
|
|
|
|
void MakeFromCopyOf(SOutlineList *ol);
|
|
|
|
};
|
|
|
|
|
2008-07-06 07:56:24 +00:00
|
|
|
class SKdNode {
|
2008-05-27 09:52:36 +00:00
|
|
|
public:
|
2016-03-22 05:03:12 +00:00
|
|
|
struct EdgeOnInfo {
|
|
|
|
int count;
|
|
|
|
bool frontFacing;
|
|
|
|
bool intersectsMesh;
|
2016-03-22 10:52:09 +00:00
|
|
|
STriangle *tr;
|
|
|
|
int ai;
|
|
|
|
int bi;
|
2016-03-22 05:03:12 +00:00
|
|
|
};
|
|
|
|
|
2009-11-09 11:51:38 +00:00
|
|
|
int which; // whether c is x, y, or z
|
2008-05-27 09:52:36 +00:00
|
|
|
double c;
|
|
|
|
|
2008-07-06 07:56:24 +00:00
|
|
|
SKdNode *gt;
|
|
|
|
SKdNode *lt;
|
2008-05-27 09:52:36 +00:00
|
|
|
|
2008-06-30 09:34:03 +00:00
|
|
|
STriangleLl *tris;
|
2008-07-06 07:56:24 +00:00
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
static SKdNode *Alloc();
|
2008-07-06 07:56:24 +00:00
|
|
|
static SKdNode *From(SMesh *m);
|
2009-11-09 11:51:38 +00:00
|
|
|
static SKdNode *From(STriangleLl *tll);
|
2008-07-06 07:56:24 +00:00
|
|
|
|
|
|
|
void AddTriangle(STriangle *tr);
|
2016-05-21 05:18:00 +00:00
|
|
|
void MakeMeshInto(SMesh *m) const;
|
|
|
|
void ListTrianglesInto(std::vector<STriangle *> *tl) const;
|
|
|
|
void ClearTags() const;
|
2009-05-22 10:02:02 +00:00
|
|
|
|
2016-05-21 05:18:00 +00:00
|
|
|
void FindEdgeOn(Vector a, Vector b, int cnt, bool coplanarIsInter, EdgeOnInfo *info) const;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void MakeCertainEdgesInto(SEdgeList *sel, EdgeKind how, bool coplanarIsInter,
|
2016-05-21 05:18:00 +00:00
|
|
|
bool *inter, bool *leaky, int auxA = 0) const;
|
2016-06-26 06:39:27 +00:00
|
|
|
void MakeOutlinesInto(SOutlineList *sel, EdgeKind tagKind) const;
|
2009-03-17 16:33:46 +00:00
|
|
|
|
2016-07-21 20:27:53 +00:00
|
|
|
void OcclusionTestLine(SEdge orig, SEdgeList *sel, int cnt) const;
|
|
|
|
void SplitLinesAgainstTriangle(SEdgeList *sel, STriangle *tr) const;
|
2009-05-28 07:07:54 +00:00
|
|
|
|
|
|
|
void SnapToMesh(SMesh *m);
|
|
|
|
void SnapToVertex(Vector v, SMesh *extras);
|
2008-05-27 09:52:36 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 09:06:30 +00:00
|
|
|
class PolylineBuilder {
|
|
|
|
public:
|
|
|
|
struct Edge;
|
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
Vector pos;
|
|
|
|
std::vector<Edge *> edges;
|
|
|
|
|
|
|
|
bool GetNext(uint32_t kind, Vertex **next, Edge **nextEdge);
|
|
|
|
bool GetNext(uint32_t kind, Vector plane, double d, Vertex **next, Edge **nextEdge);
|
|
|
|
size_t CountEdgesWithTagAndKind(int tag, uint32_t kind) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexPairHash {
|
|
|
|
size_t operator()(const std::pair<Vertex *, Vertex *> &v) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Edge {
|
|
|
|
Vertex *a;
|
|
|
|
Vertex *b;
|
|
|
|
uint32_t kind;
|
|
|
|
int tag;
|
|
|
|
|
|
|
|
union {
|
|
|
|
uintptr_t data;
|
|
|
|
SOutline *outline;
|
|
|
|
SEdge *edge;
|
|
|
|
};
|
|
|
|
|
|
|
|
Vertex *GetOtherVertex(Vertex *v) const;
|
|
|
|
bool GetStartAndNext(Vertex **start, Vertex **next, bool loop) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<Vector, Vertex *, VectorHash, VectorPred> vertices;
|
|
|
|
std::unordered_map<std::pair<Vertex *, Vertex *>, Edge *, VertexPairHash> edgeMap;
|
|
|
|
std::vector<Edge *> edges;
|
|
|
|
|
|
|
|
~PolylineBuilder();
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
Vertex *AddVertex(const Vector &pos);
|
|
|
|
Edge *AddEdge(const Vector &p0, const Vector &p1, uint32_t kind, uintptr_t data = 0);
|
2019-11-23 14:07:31 +00:00
|
|
|
void Generate(std::function<void(Vertex *start, Vertex *next, Edge *edge)> const &startFunc,
|
|
|
|
std::function<void(Vertex *next, Edge *edge)> const &nextFunc,
|
|
|
|
std::function<void(Edge *)> const &aloneFunc,
|
|
|
|
std::function<void()> const &endFunc = []() {});
|
2016-10-11 10:38:21 +00:00
|
|
|
|
|
|
|
void MakeFromEdges(const SEdgeList &sel);
|
|
|
|
void MakeFromOutlines(const SOutlineList &sol);
|
|
|
|
void GenerateEdges(SEdgeList *sel);
|
|
|
|
void GenerateOutlines(SOutlineList *sol);
|
2016-06-24 09:06:30 +00:00
|
|
|
};
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
#endif
|
2008-04-24 06:22:16 +00:00
|
|
|
|