Files
test/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp

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

327 lines
7.7 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup freestyle
2019-07-07 15:38:41 +10:00
* \brief A Set of indexed faces to represent a surface object
*/
2008-04-30 15:41:54 +00:00
#include "IndexedFaceSet.h"
#include "BLI_sys_types.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 {
IndexedFaceSet::IndexedFaceSet()
2008-04-30 15:41:54 +00:00
{
_Vertices = nullptr;
_Normals = nullptr;
_FrsMaterials = nullptr;
_TexCoords = nullptr;
_FaceEdgeMarks = nullptr;
_VSize = 0;
_NSize = 0;
_MSize = 0;
_TSize = 0;
_NumFaces = 0;
_NumVertexPerFace = nullptr;
_FaceStyle = nullptr;
_VIndices = nullptr;
_VISize = 0;
_NIndices = nullptr;
_NISize = 0;
_MIndices = nullptr;
_MISize = 0;
_TIndices = nullptr;
_TISize = 0;
2008-04-30 15:41:54 +00:00
}
IndexedFaceSet::IndexedFaceSet(float *iVertices,
uint iVSize,
float *iNormals,
uint iNSize,
FrsMaterial **iMaterials,
uint iMSize,
float *iTexCoords,
uint iTSize,
uint iNumFaces,
uint *iNumVertexPerFace,
TRIANGLES_STYLE *iFaceStyle,
FaceEdgeMark *iFaceEdgeMarks,
uint *iVIndices,
uint iVISize,
uint *iNIndices,
uint iNISize,
uint *iMIndices,
uint iMISize,
uint *iTIndices,
uint iTISize,
uint iCopy)
2008-04-30 15:41:54 +00:00
{
if (1 == iCopy) {
_VSize = iVSize;
_Vertices = new float[_VSize];
memcpy(_Vertices, iVertices, iVSize * sizeof(float));
_NSize = iNSize;
_Normals = new float[_NSize];
memcpy(_Normals, iNormals, iNSize * sizeof(float));
_MSize = iMSize;
_FrsMaterials = nullptr;
if (iMaterials) {
_FrsMaterials = new FrsMaterial *[_MSize];
for (uint i = 0; i < _MSize; ++i) {
_FrsMaterials[i] = new FrsMaterial(*(iMaterials[i]));
}
}
_TSize = iTSize;
_TexCoords = nullptr;
if (_TSize) {
_TexCoords = new float[_TSize];
memcpy(_TexCoords, iTexCoords, iTSize * sizeof(float));
}
_NumFaces = iNumFaces;
_NumVertexPerFace = new uint[_NumFaces];
memcpy(_NumVertexPerFace, iNumVertexPerFace, _NumFaces * sizeof(uint));
_FaceStyle = new TRIANGLES_STYLE[_NumFaces];
memcpy(_FaceStyle, iFaceStyle, _NumFaces * sizeof(TRIANGLES_STYLE));
_FaceEdgeMarks = new FaceEdgeMark[_NumFaces];
memcpy(_FaceEdgeMarks, iFaceEdgeMarks, _NumFaces * sizeof(FaceEdgeMark));
_VISize = iVISize;
_VIndices = new uint[_VISize];
memcpy(_VIndices, iVIndices, _VISize * sizeof(uint));
_NISize = iNISize;
_NIndices = new uint[_NISize];
memcpy(_NIndices, iNIndices, _NISize * sizeof(uint));
_MISize = iMISize;
_MIndices = nullptr;
if (iMIndices) {
_MIndices = new uint[_MISize];
memcpy(_MIndices, iMIndices, _MISize * sizeof(uint));
2008-04-30 15:41:54 +00:00
}
_TISize = iTISize;
_TIndices = nullptr;
if (_TISize) {
_TIndices = new uint[_TISize];
memcpy(_TIndices, iTIndices, _TISize * sizeof(uint));
}
}
else {
_VSize = iVSize;
_Vertices = iVertices;
_NSize = iNSize;
_Normals = iNormals;
_MSize = iMSize;
_FrsMaterials = nullptr;
if (iMaterials) {
_FrsMaterials = iMaterials;
}
_TSize = iTSize;
_TexCoords = iTexCoords;
_NumFaces = iNumFaces;
_NumVertexPerFace = iNumVertexPerFace;
_FaceStyle = iFaceStyle;
_FaceEdgeMarks = iFaceEdgeMarks;
_VISize = iVISize;
_VIndices = iVIndices;
_NISize = iNISize;
_NIndices = iNIndices;
_MISize = iMISize;
_MIndices = nullptr;
if (iMISize) {
2008-04-30 15:41:54 +00:00
_MIndices = iMIndices;
}
_TISize = iTISize;
_TIndices = iTIndices;
}
2008-04-30 15:41:54 +00:00
}
IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet &iBrother) : Rep(iBrother)
2008-04-30 15:41:54 +00:00
{
_VSize = iBrother.vsize();
_Vertices = new float[_VSize];
memcpy(_Vertices, iBrother.vertices(), _VSize * sizeof(float));
_NSize = iBrother.nsize();
_Normals = new float[_NSize];
memcpy(_Normals, iBrother.normals(), _NSize * sizeof(float));
_MSize = iBrother.msize();
if (_MSize) {
_FrsMaterials = new FrsMaterial *[_MSize];
for (uint i = 0; i < _MSize; ++i) {
_FrsMaterials[i] = new FrsMaterial(*(iBrother._FrsMaterials[i]));
2008-04-30 15:41:54 +00:00
}
}
else {
_FrsMaterials = nullptr;
2008-04-30 15:41:54 +00:00
}
_TSize = iBrother.tsize();
_TexCoords = nullptr;
if (_TSize) {
_TexCoords = new float[_TSize];
memcpy(_TexCoords, iBrother.texCoords(), _TSize * sizeof(float));
}
_NumFaces = iBrother.numFaces();
_NumVertexPerFace = new uint[_NumFaces];
memcpy(_NumVertexPerFace, iBrother.numVertexPerFaces(), _NumFaces * sizeof(uint));
_FaceStyle = new TRIANGLES_STYLE[_NumFaces];
memcpy(_FaceStyle, iBrother.trianglesStyle(), _NumFaces * sizeof(TRIANGLES_STYLE));
_FaceEdgeMarks = new FaceEdgeMark[_NumFaces];
memcpy(_FaceEdgeMarks, iBrother.faceEdgeMarks(), _NumFaces * sizeof(FaceEdgeMark));
_VISize = iBrother.visize();
_VIndices = new uint[_VISize];
memcpy(_VIndices, iBrother.vindices(), _VISize * sizeof(uint));
_NISize = iBrother.nisize();
_NIndices = new uint[_NISize];
memcpy(_NIndices, iBrother.nindices(), _NISize * sizeof(uint));
_MISize = iBrother.misize();
if (_MISize) {
_MIndices = new uint[_MISize];
memcpy(_MIndices, iBrother.mindices(), _MISize * sizeof(uint));
}
else {
_MIndices = nullptr;
2008-04-30 15:41:54 +00:00
}
_TISize = iBrother.tisize();
_TIndices = nullptr;
if (_TISize) {
_TIndices = new uint[_TISize];
memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(uint));
}
2008-04-30 15:41:54 +00:00
}
IndexedFaceSet::~IndexedFaceSet()
{
if (nullptr != _Vertices) {
delete[] _Vertices;
_Vertices = nullptr;
}
if (nullptr != _Normals) {
delete[] _Normals;
_Normals = nullptr;
}
if (nullptr != _FrsMaterials) {
for (uint i = 0; i < _MSize; ++i) {
delete _FrsMaterials[i];
}
delete[] _FrsMaterials;
_FrsMaterials = nullptr;
}
if (nullptr != _TexCoords) {
delete[] _TexCoords;
_TexCoords = nullptr;
}
if (nullptr != _NumVertexPerFace) {
delete[] _NumVertexPerFace;
_NumVertexPerFace = nullptr;
}
if (nullptr != _FaceStyle) {
delete[] _FaceStyle;
_FaceStyle = nullptr;
}
if (nullptr != _FaceEdgeMarks) {
delete[] _FaceEdgeMarks;
_FaceEdgeMarks = nullptr;
}
if (nullptr != _VIndices) {
delete[] _VIndices;
_VIndices = nullptr;
}
if (nullptr != _NIndices) {
delete[] _NIndices;
_NIndices = nullptr;
}
if (nullptr != _MIndices) {
delete[] _MIndices;
_MIndices = nullptr;
}
if (nullptr != _TIndices) {
delete[] _TIndices;
_TIndices = nullptr;
}
2008-04-30 15:41:54 +00:00
}
void IndexedFaceSet::accept(SceneVisitor &v)
{
Rep::accept(v);
v.visitIndexedFaceSet(*this);
2008-04-30 15:41:54 +00:00
}
void IndexedFaceSet::ComputeBBox()
{
float XMax = _Vertices[0];
float YMax = _Vertices[1];
float ZMax = _Vertices[2];
float XMin = _Vertices[0];
float YMin = _Vertices[1];
float ZMin = _Vertices[2];
// parse all the coordinates to find the Xmax, YMax, ZMax
float *v = _Vertices;
for (uint i = 0; i < (_VSize / 3); ++i) {
if (*v > XMax) {
XMax = *v;
}
if (*v < XMin) {
XMin = *v;
}
++v;
if (*v > YMax) {
YMax = *v;
}
if (*v < YMin) {
YMin = *v;
}
++v;
if (*v > ZMax) {
ZMax = *v;
}
if (*v < ZMin) {
ZMin = *v;
}
++v;
}
setBBox(BBox<Vec3f>(Vec3f(XMin, YMin, ZMin), Vec3f(XMax, YMax, ZMax)));
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 */