Files
test2/source/blender/freestyle/intern/view_map/Interface0D.h

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

323 lines
7.2 KiB
C
Raw Normal View History

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2008-04-30 15:41:54 +00:00
#pragma once
2008-04-30 15:41:54 +00:00
/** \file
* \ingroup freestyle
2023-06-28 12:21:56 +10:00
* \brief Interface to 0D elements.
*/
#include <iostream>
#include <string>
#include "../geometry/Geom.h"
2008-04-30 15:41:54 +00:00
#include "../system/Id.h"
#include "../system/Iterator.h"
#include "../system/Precision.h"
#include "../winged_edge/Nature.h"
#include "MEM_guardedalloc.h"
using namespace std;
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
//
// Interface0D
//
//////////////////////////////////////////////////
class FEdge;
class SVertex;
class ViewVertex;
class NonTVertex;
class TVertex;
/** Base class for any 0D element. */
2008-04-30 15:41:54 +00:00
class Interface0D {
public:
/** Default constructor */
Interface0D() {}
/** Destructor */
virtual ~Interface0D(){};
/** Returns the string "Interface0D". */
virtual string getExactTypeName() const
{
return "Interface0D";
}
// Data access methods
/** Returns the 3D x coordinate of the point. */
virtual real getX() const;
/** Returns the 3D y coordinate of the point. */
virtual real getY() const;
/** Returns the 3D z coordinate of the point. */
virtual real getZ() const;
/** Returns the 3D point. */
virtual Geometry::Vec3r getPoint3D() const;
/** Returns the 2D x coordinate of the point. */
virtual real getProjectedX() const;
/** Returns the 2D y coordinate of the point. */
virtual real getProjectedY() const;
/** Returns the 2D z coordinate of the point. */
virtual real getProjectedZ() const;
/** Returns the 2D point. */
virtual Geometry::Vec2r getPoint2D() const;
/** Returns the FEdge that lies between this Interface0D and the Interface0D given as argument.
*/
virtual FEdge *getFEdge(Interface0D &);
/** Returns the Id of the point. */
virtual Id getId() const;
/** Returns the nature of the point. */
virtual Nature::VertexNature getNature() const;
/** Cast the Interface0D in SVertex if it can be. */
virtual SVertex *castToSVertex();
/** Cast the Interface0D in ViewVertex if it can be. */
virtual ViewVertex *castToViewVertex();
/** Cast the Interface0D in NonTVertex if it can be. */
virtual NonTVertex *castToNonTVertex();
/** Cast the Interface0D in TVertex if it can be. */
virtual TVertex *castToTVertex();
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface0D")
2008-04-30 15:41:54 +00:00
};
//
// Interface0DIteratorNested
//
//////////////////////////////////////////////////
class Interface0DIteratorNested : public Iterator {
2008-04-30 15:41:54 +00:00
public:
virtual ~Interface0DIteratorNested() {}
2008-04-30 15:41:54 +00:00
virtual string getExactTypeName() const
{
return "Interface0DIteratorNested";
}
2008-04-30 15:41:54 +00:00
virtual Interface0D &operator*() = 0;
2008-04-30 15:41:54 +00:00
virtual Interface0D *operator->()
{
return &(operator*());
}
2008-04-30 15:41:54 +00:00
virtual int increment() = 0;
2008-04-30 15:41:54 +00:00
virtual int decrement() = 0;
2008-04-30 15:41:54 +00:00
virtual bool isBegin() const = 0;
2008-04-30 15:41:54 +00:00
virtual bool isEnd() const = 0;
2008-04-30 15:41:54 +00:00
virtual bool operator==(const Interface0DIteratorNested &it) const = 0;
2008-04-30 15:41:54 +00:00
virtual bool operator!=(const Interface0DIteratorNested &it) const
{
return !(*this == it);
}
2008-04-30 15:41:54 +00:00
/** Returns the curvilinear abscissa */
virtual float t() const = 0;
2008-04-30 15:41:54 +00:00
/** Returns the point parameter 0<u<1 */
virtual float u() const = 0;
2008-04-30 15:41:54 +00:00
virtual Interface0DIteratorNested *copy() const = 0;
2008-04-30 15:41:54 +00:00
};
//
// Interface0DIterator
//
//////////////////////////////////////////////////
/** Class defining an iterator over Interface0D elements.
* An instance of this iterator is always obtained from a 1D element.
* \attention In the scripting language, you must call \code it2 = Interface0DIterator(it1)
* \endcode instead of \code it2 = it1 \endcode where \a it1 and \a it2 are 2 Interface0DIterator.
2008-04-30 15:41:54 +00:00
* Otherwise, incrementing \a it1 will also increment \a it2.
*/
class Interface0DIterator : public Iterator {
2008-04-30 15:41:54 +00:00
public:
Interface0DIterator(Interface0DIteratorNested *it = nullptr)
{
_iterator = it;
}
/** Copy constructor */
Interface0DIterator(const Interface0DIterator &it)
{
_iterator = it._iterator->copy();
}
/** Destructor */
virtual ~Interface0DIterator()
{
if (_iterator) {
delete _iterator;
}
}
/** Operator =
* \attention In the scripting language, you must call \code it2 = Interface0DIterator(it1)
* \endcode instead of \code it2 = it1 \endcode where \a it1 and \a it2 are 2
* Interface0DIterator. Otherwise, incrementing \a it1 will also increment \a it2.
*/
Interface0DIterator &operator=(const Interface0DIterator &it)
{
if (_iterator) {
delete _iterator;
}
_iterator = it._iterator->copy();
return *this;
}
/** Returns the string "Interface0DIterator". */
virtual string getExactTypeName() const
{
if (!_iterator) {
return "Interface0DIterator";
}
return _iterator->getExactTypeName() + "Proxy";
}
// FIXME test it != 0 (exceptions ?)
/** Returns a reference to the pointed Interface0D.
* In the scripting language, you must call "getObject()" instead using this operator.
*/
Interface0D &operator*()
{
return _iterator->operator*();
}
/** Returns a pointer to the pointed Interface0D.
* Can't be called in the scripting language.
*/
Interface0D *operator->()
{
return &(operator*());
}
/** Increments. In the scripting language, call "increment()". */
Interface0DIterator &operator++()
{
_iterator->increment();
return *this;
}
/** Increments. In the scripting language, call "increment()". */
Interface0DIterator operator++(int)
{
Interface0DIterator ret(*this);
_iterator->increment();
return ret;
}
/** Decrements. In the scripting language, call "decrement()". */
Interface0DIterator &operator--()
{
_iterator->decrement();
return *this;
}
/** Decrements. In the scripting language, call "decrement()". */
Interface0DIterator operator--(int)
{
Interface0DIterator ret(*this);
_iterator->decrement();
return ret;
}
/** Increments. */
virtual int increment()
{
return _iterator->increment();
}
/** Decrements. */
virtual int decrement()
{
return _iterator->decrement();
}
/** Returns true if the pointed Interface0D is the first of the 1D element containing the points
* over which we're iterating.
*/
virtual bool isBegin() const
{
return _iterator->isBegin();
}
/** Returns true if the pointed Interface0D is after the after the last point of the 1D element
* we're iterating from. */
virtual bool isEnd() const
{
return _iterator->isEnd();
}
/** Returns true when the iterator is pointing to the final valid element. */
virtual bool atLast() const
{
if (_iterator->isEnd()) {
return false;
}
_iterator->increment();
bool result = _iterator->isEnd();
_iterator->decrement();
return result;
}
/** operator `==`. */
bool operator==(const Interface0DIterator &it) const
{
return _iterator->operator==(*(it._iterator));
}
/** operator `!=`. */
bool operator!=(const Interface0DIterator &it) const
{
return !(*this == it);
}
/** Returns the curvilinear abscissa. */
inline float t() const
{
return _iterator->t();
}
/** Returns the point parameter in the curve 0<=u<=1. */
inline float u() const
{
return _iterator->u();
}
2008-04-30 15:41:54 +00:00
protected:
Interface0DIteratorNested *_iterator;
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 */