Files
test2/source/blender/freestyle/intern/geometry/GeomCleaner.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

235 lines
7.1 KiB
C
Raw Normal View History

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup freestyle
* \brief Class to define a cleaner of geometry providing a set of useful tools
*/
#include "Geom.h"
#include "../system/FreestyleConfig.h"
2008-04-30 15:41:54 +00:00
#include "MEM_guardedalloc.h"
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
namespace Freestyle {
2008-04-30 15:41:54 +00:00
using namespace Geometry;
class GeomCleaner {
2008-04-30 15:41:54 +00:00
public:
inline GeomCleaner() {}
inline ~GeomCleaner() {}
/** Sorts an array of Indexed vertices
* iVertices
* Array of vertices to sort.
* It is organized as a float series of vertex coordinates: XYZXYZXYZ...
* iVSize
* The size of iVertices array.
* iIndices
* The array containing the vertex indices
* (used to refer to the vertex coordinates in an indexed face).
2024-09-04 19:32:41 +10:00
* Each element is a uint multiple of 3.
* iISize
* The size of iIndices array
* oVertices
* Output of sorted vertices.
* A vertex v1 precedes another one v2 in this array
* if v1.x<v2.x, or v1.x=v2.x && v1.y < v2.y or v1.x=v2.y && v1.y=v2.y && v1.z < v2.z.
2019-08-04 12:51:44 +10:00
* The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
* oIndices
* Output corresponding to the iIndices array but reorganized in
* order to match the sorted vertex array.
*/
static void SortIndexedVertexArray(const float *iVertices,
uint iVSize,
const uint *iIndices,
uint iISize,
float **oVertices,
uint **oIndices);
/** Compress a SORTED indexed vertex array by eliminating multiple
* appearing occurrences of a single vertex.
* iVertices
* The SORTED vertex array to compress.
* It is organized as a float series of vertex coordinates: XYZXYZXYZ...
* iVSize
* The size of iVertices array.
* iIndices
* The array containing the vertex indices
* (used to refer to the vertex coordinates in an indexed face).
2024-09-04 19:32:41 +10:00
* Each element is a uint multiple of 3.
* iISize
* The size of iIndices array
* oVertices
* The vertex array, result of the compression.
2019-08-04 12:51:44 +10:00
* The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
* oVSize
* The size of oVertices.
* oIndices
* The indices array, reorganized to match the compressed oVertices array.
*/
static void CompressIndexedVertexArray(const float *iVertices,
uint iVSize,
const uint *iIndices,
uint iISize,
float **oVertices,
uint *oVSize,
uint **oIndices);
/** Sorts and compress an array of indexed vertices.
* iVertices
* The vertex array to sort then compress. It is organized as a float series of
* vertex coordinates: XYZXYZXYZ...
* iVSize
* The size of iVertices array.
* iIndices
* The array containing the vertex indices
* (used to refer to the vertex coordinates in an indexed face).
2024-09-04 19:32:41 +10:00
* Each element is a uint multiple of 3.
* iISize
* The size of iIndices array
* oVertices
* The vertex array, result of the sorting-compression.
2019-08-04 12:51:44 +10:00
* The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
* oVSize
* The size of oVertices.
* oIndices
* The indices array, reorganized to match the sorted and compressed oVertices array.
*/
static void SortAndCompressIndexedVertexArray(const float *iVertices,
uint iVSize,
const uint *iIndices,
uint iISize,
float **oVertices,
uint *oVSize,
uint **oIndices);
/** Cleans an indexed vertex array.
* (Identical to SortAndCompress except that we use here a hash table to create the new array.)
* iVertices
* The vertex array to sort then compress. It is organized as a float series of
* vertex coordinates: XYZXYZXYZ...
* iVSize
* The size of iVertices array.
* iIndices
* The array containing the vertex indices
* (used to refer to the vertex coordinates in an indexed face).
2024-09-04 19:32:41 +10:00
* Each element is a uint multiple of 3.
* iISize
* The size of iIndices array
* oVertices
* The vertex array, result of the sorting-compression.
2019-08-04 12:51:44 +10:00
* The array is organized as a 3-float series giving the vertices coordinates: XYZXYZXYZ...
* oVSize
* The size of oVertices.
* oIndices
* The indices array, reorganized to match the sorted and compressed oVertices array.
*/
static void CleanIndexedVertexArray(const float *iVertices,
uint iVSize,
const uint *iIndices,
uint iISize,
float **oVertices,
uint *oVSize,
uint **oIndices);
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GeomCleaner")
2008-04-30 15:41:54 +00:00
};
/** Binary operators */
// inline bool operator<(const IndexedVertex& iv1, const IndexedVertex& iv2);
2008-04-30 15:41:54 +00:00
/** Class Indexed Vertex. Used to represent an indexed vertex by storing the vertex coordinates as
* well as its index */
2008-04-30 15:41:54 +00:00
class IndexedVertex {
private:
Vec3f _Vector;
uint _index;
2008-04-30 15:41:54 +00:00
public:
inline IndexedVertex() {}
inline IndexedVertex(Vec3f iVector, uint iIndex)
{
_Vector = iVector;
_index = iIndex;
}
/** accessors */
inline const Vec3f &vector() const
{
return _Vector;
}
inline uint index()
{
return _index;
}
inline float x()
{
return _Vector[0];
}
inline float y()
{
return _Vector[1];
}
inline float z()
{
return _Vector[2];
}
/** modifiers */
inline void setVector(const Vec3f &iVector)
{
_Vector = iVector;
}
inline void setIndex(uint iIndex)
{
_index = iIndex;
}
/** operators */
IndexedVertex &operator=(const IndexedVertex &iv)
{
_Vector = iv._Vector;
_index = iv._index;
return *this;
}
inline float operator[](const uint i)
{
return _Vector[i];
}
// friend inline bool operator<(const IndexedVertex& iv1, const IndexedVertex& iv2);
inline bool operator<(const IndexedVertex &v) const
{
return (_Vector < v._Vector);
}
inline bool operator==(const IndexedVertex &v)
{
return (_Vector == v._Vector);
}
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedVertex")
2008-04-30 15:41:54 +00:00
};
#if 0
bool operator<(const IndexedVertex &iv1, const IndexedVertex &iv2)
{
return iv1.operator<(iv2);
}
#endif
2008-04-30 15:41:54 +00:00
Attempt to fix a potential name conflict between Freestyle and the compositor. A crash in the Freestyle renderer was reported by Ton on IRC with a stack trace below. Note that #2 is in Freestyle, whereas #1 is in the compositor. The problem was observed in a debug build on OS X 10.7 (gcc 4.2, openmp disabled, no llvm). ---------------------------------------------------------------------- Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 72386 thread 0xf303] 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 43 delete (this->m_outputsockets.back()); Current language: auto; currently c++ (gdb) where #0 0x0000000100c129f3 in NodeBase::~NodeBase (this=0x10e501c80) at COM_NodeBase.cpp:43 #1 0x0000000100c29066 in Node::~Node (this=0x10e501c80) at COM_Node.h:49 #2 0x000000010089c273 in NodeShape::~NodeShape (this=0x10e501c80) at NodeShape.cpp:43 #3 0x000000010089910b in NodeGroup::destroy (this=0x10e501da0) at NodeGroup.cpp:61 #4 0x00000001008990cd in NodeGroup::destroy (this=0x10e5014b0) at NodeGroup.cpp:59 #5 0x00000001008990cd in NodeGroup::destroy (this=0x114e18da0) at NodeGroup.cpp:59 #6 0x00000001007e6602 in Controller::ClearRootNode (this=0x114e19640) at Controller.cpp:329 #7 0x00000001007ea52e in Controller::LoadMesh (this=0x114e19640, re=0x10aba4638, srl=0x1140f5258) at Controller.cpp:302 #8 0x00000001008030ad in prepare (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:302 #9 0x000000010080457a in FRS_do_stroke_rendering (re=0x10aba4638, srl=0x1140f5258) at FRS_freestyle.cpp:600 #10 0x00000001006aeb9d in add_freestyle (re=0x10aba4638) at pipeline.c:1584 #11 0x00000001006aceb7 in do_render_3d (re=0x10aba4638) at pipeline.c:1094 #12 0x00000001006ae061 in do_render_fields_blur_3d (re=0x10aba4638) at pipeline.c:1367 #13 0x00000001006afa16 in do_render_composite_fields_blur_3d (re=0x10aba4638) at pipeline.c:1815 #14 0x00000001006b04e4 in do_render_all_options (re=0x10aba4638) at pipeline.c:2021 ---------------------------------------------------------------------- Apparently a name conflict between the two Blender modules is taking place. The present commit hence intends to address it by putting all the Freestyle C++ classes in the namespace 'Freestyle'. This revision will also prevent potential name conflicts with other Blender modules in the future. Special thanks to Lukas Toenne for the help with C++ namespace.
2013-04-09 00:46:49 +00:00
} /* namespace Freestyle */