==================================
Merging Carve library integration project into the trunk.
This commit switches Boolean modifier to another library which handles
mesh boolean operations in much stable and faster way, resolving old
well-known limitations of intern boolop library.
Carve is integrating as alternative interface for boolop library and
which makes it totally transparent for blender sources to switch between
old-fashioned boolop and new Carve backends.
Detailed changes in this commit:
- Integrated needed subset of Carve library sources into extern/
Added script for re-bundling it (currently works only if repo
was cloned by git-svn).
- Added BOP_CarveInterface for boolop library which can be used by
Boolean modifier.
- Carve backend is enabled by default, can be disabled by WITH_BF_CARVE
SCons option and WITH_CARVE CMake option.
- If Boost library is found in build environment it'll be used for
unordered collections. If Boost isn't found, it'll fallback to TR1
implementation for GCC compilers. Boost is obligatory if MSVC is used.
Tested on Linux 64bit and Windows 7 64bit.
NOTE: behavior of flat objects was changed. E.g. Plane-Sphere now gives
plane with circle hole, not plane with semisphere. Don't think
it's really issue because it's not actually defined behavior in
such situations and both of ways might be useful. Since it's
only known "regression" think it's OK to deal with it.
Details are there http://wiki.blender.org/index.php/User:Nazg-gul/CarveBooleans
Special thanks to:
- Ken Hughes: author of original carve integration patch.
- Campbell Barton: help in project development, review tests.
- Tobias Sargeant: author of Carve library, help in resolving some
merge stoppers, bug fixing.
250 lines
6.3 KiB
C++
250 lines
6.3 KiB
C++
/*
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
* All rights reserved.
|
|
*
|
|
* The Original Code is: all of this file.
|
|
*
|
|
* Contributor(s): none yet.
|
|
*
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
*/
|
|
|
|
/** \file boolop/intern/BOP_Segment.cpp
|
|
* \ingroup boolopintern
|
|
*/
|
|
|
|
|
|
#include "BOP_Segment.h"
|
|
|
|
#define UNDEFINED 0
|
|
|
|
/**
|
|
* Constructs a new segment.
|
|
*/
|
|
BOP_Segment::BOP_Segment(){
|
|
m_cfg1 = UNDEFINED;
|
|
m_cfg2 = UNDEFINED;
|
|
}
|
|
|
|
/**
|
|
* Returns the relative edge index between two relative vertex indices.
|
|
* @param v1 relative vertex index
|
|
* @param v2 relative vertex index
|
|
* @return relative edge index between two relative vertex indices, -1 otherwise
|
|
*/
|
|
int BOP_Segment::getEdgeBetween(unsigned int v1, unsigned int v2)
|
|
{
|
|
if ((v1 == 1 && v2 == 2) || (v1 == 2 && v2 == 1)) return 1;
|
|
if ((v1 == 3 && v2 == 2) || (v1 == 2 && v2 == 3)) return 2;
|
|
if ((v1 == 1 && v2 == 3) || (v1 == 3 && v2 == 1)) return 3;
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* Returns if a relative vertex index is on a relative edge index.
|
|
* @param v relative vertex index
|
|
* @param e relative edge index
|
|
* @return true if the relative vertex index is on the relative edge index,
|
|
* false otherwise.
|
|
*/
|
|
bool BOP_Segment::isOnEdge(unsigned int v, unsigned int e)
|
|
{
|
|
if (v == 1 && (e == 1 || e == 3)) return true;
|
|
if (v == 2 && (e == 1 || e == 2)) return true;
|
|
if (v == 3 && (e == 2 || e == 3)) return true;
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Inverts the segment, swapping ends data.
|
|
*/
|
|
void BOP_Segment::invert()
|
|
{
|
|
BOP_Index aux = m_v1;
|
|
m_v1 = m_v2;
|
|
m_v2 = aux;
|
|
aux = m_cfg1;
|
|
m_cfg1 = m_cfg2;
|
|
m_cfg2 = aux;
|
|
}
|
|
|
|
/**
|
|
* Sorts the segment according to ends configuration.
|
|
* The criterion to sort is ...
|
|
*
|
|
* UNDEFINED < VERTEX < EDGE < IN
|
|
* cfg1 > cfg2
|
|
*
|
|
* so ...
|
|
*
|
|
* VERTEX(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2)
|
|
* EDGE(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2) || EDGE(cfg2)
|
|
* IN(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2) || EDGE(cfg2) || IN(cfg2)
|
|
*/
|
|
void BOP_Segment::sort()
|
|
{
|
|
if (m_cfg1 < m_cfg2) invert();
|
|
}
|
|
|
|
/**
|
|
* Returns if the specified end segment configuration is IN.
|
|
* @return true if the specified end segment configuration is IN, false otherwise
|
|
*/
|
|
bool BOP_Segment::isIn(unsigned int cfg)
|
|
{
|
|
return (cfg == 20);
|
|
}
|
|
|
|
/**
|
|
* Returns if the specified end segment configuration is EDGE.
|
|
* @return true if the specified end segment configuration is EDGE, false otherwise
|
|
*/
|
|
bool BOP_Segment::isEdge(unsigned int cfg)
|
|
{
|
|
return (cfg > 10) && (cfg < 20);
|
|
}
|
|
|
|
/**
|
|
* Returns if the specified end segment configuration is VERTEX.
|
|
* @return true if the specified end segment configuration is VERTEX, false otherwise
|
|
*/
|
|
bool BOP_Segment::isVertex(unsigned int cfg)
|
|
{
|
|
return (cfg!=UNDEFINED) && (cfg < 10);
|
|
}
|
|
|
|
/**
|
|
* Returns if the specified end segment configuration is DEFINED (not UNDEFINED).
|
|
* @return true if the specified end segment configuration is DEFINED, false otherwise
|
|
*/
|
|
bool BOP_Segment::isDefined(unsigned int cfg)
|
|
{
|
|
return (cfg != UNDEFINED);
|
|
}
|
|
|
|
/**
|
|
* Returns if the specified end segment configuration is UNDEFINED.
|
|
* @return true if the specified end segment configuration is UNDEFINED, false otherwise
|
|
*/
|
|
bool BOP_Segment::isUndefined(unsigned int cfg)
|
|
{
|
|
return (cfg == UNDEFINED);
|
|
}
|
|
|
|
/**
|
|
* Returns the relative edge index from the specified end segment configuration.
|
|
* @return relative edge index from the specified end segment configuration
|
|
*/
|
|
unsigned int BOP_Segment::getEdge(unsigned int cfg)
|
|
{
|
|
return cfg-10;
|
|
}
|
|
|
|
/**
|
|
* Returns the relative vertex index from the specified end segment configuration.
|
|
* @return relative vertex index from the specified end segment configuration
|
|
*/
|
|
BOP_Index BOP_Segment::getVertex(unsigned int cfg)
|
|
{
|
|
return cfg;
|
|
}
|
|
|
|
/**
|
|
* Returns the end segment configuration for the specified relative edge index.
|
|
* @return end segment configuration for the specified relative edge index
|
|
*/
|
|
unsigned int BOP_Segment::createEdgeCfg(unsigned int edge)
|
|
{
|
|
return 10+edge;
|
|
}
|
|
|
|
/**
|
|
* Returns the end segment configuration for the specified relative vertex index.
|
|
* @return end segment configuration for the specified relative vertex index
|
|
*/
|
|
unsigned int BOP_Segment::createVertexCfg(BOP_Index vertex)
|
|
{
|
|
return vertex;
|
|
}
|
|
|
|
/**
|
|
* Returns the end segment IN configuration.
|
|
* @return end segment IN configuration
|
|
*/
|
|
unsigned int BOP_Segment::createInCfg()
|
|
{
|
|
return 20;
|
|
}
|
|
|
|
/**
|
|
* Returns the end segment UNDEFINED configuration.
|
|
* @return end segment UNDEFINED configuration
|
|
*/
|
|
unsigned int BOP_Segment::createUndefinedCfg()
|
|
{
|
|
return UNDEFINED;
|
|
}
|
|
|
|
/**
|
|
* Returns the inner segment configuration.
|
|
* @return inner segment configuration
|
|
*/
|
|
unsigned int BOP_Segment::getConfig()
|
|
{
|
|
if (isUndefined(m_cfg1)) return m_cfg2;
|
|
else if (isUndefined(m_cfg2)) return m_cfg1;
|
|
else if (isVertex(m_cfg1)) {
|
|
// v1 is vertex
|
|
if (isVertex(m_cfg2)) {
|
|
// v2 is vertex
|
|
return createEdgeCfg(getEdgeBetween(getVertex(m_cfg1),getVertex(m_cfg2)));
|
|
}
|
|
else if (isEdge(m_cfg2)) {
|
|
// v2 is edge
|
|
if (isOnEdge(m_cfg1,getEdge(m_cfg2))) return m_cfg2;
|
|
else return createInCfg(); //IN
|
|
}
|
|
else return createInCfg(); //IN
|
|
}
|
|
else if (isEdge(m_cfg1)) {
|
|
// v1 is edge
|
|
if (isVertex(m_cfg2)) {
|
|
// v2 is vertex
|
|
if (isOnEdge(m_cfg2,getEdge(m_cfg1))) return m_cfg1;
|
|
else return createInCfg(); //IN
|
|
}
|
|
else if (isEdge(m_cfg2)) {
|
|
// v2 is edge
|
|
if (m_cfg1 == m_cfg2) return m_cfg1;
|
|
else return createInCfg(); // IN
|
|
}
|
|
else return createInCfg(); // IN
|
|
}
|
|
else return createInCfg(); // IN
|
|
}
|
|
|
|
/**
|
|
* Implements operator <<
|
|
*/
|
|
std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c)
|
|
{
|
|
std::cout << "m_v1: " << c.m_v1 << "(" << c.m_cfg1 << ") m_v2: " << c.m_v2 << "(" << c.m_cfg2 << ")";
|
|
return stream;
|
|
}
|