[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50523] trunk/blender/intern/bsp/intern: Hopefully this would restore svn history for Carve interface

Sergey Sharybin sergey.vfx at gmail.com
Tue Sep 11 11:23:04 CEST 2012


Revision: 50523
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50523
Author:   nazgul
Date:     2012-09-11 09:23:04 +0000 (Tue, 11 Sep 2012)
Log Message:
-----------
Hopefully this would restore svn history for Carve interface

Added Paths:
-----------
    trunk/blender/intern/bsp/intern/BOP_CarveInterface.cpp

Removed Paths:
-------------
    trunk/blender/intern/bsp/intern/BOP_CarveInterface.cpp

Deleted: trunk/blender/intern/bsp/intern/BOP_CarveInterface.cpp
===================================================================
--- trunk/blender/intern/bsp/intern/BOP_CarveInterface.cpp	2012-09-11 09:13:57 UTC (rev 50522)
+++ trunk/blender/intern/bsp/intern/BOP_CarveInterface.cpp	2012-09-11 09:23:04 UTC (rev 50523)
@@ -1,834 +0,0 @@
-/*
- * ***** 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) 2010 by the Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Ken Hughes,
- *                 Sergey Sharybin.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file bsp/intern/BOP_CarveInterface.cpp
- *  \ingroup bsp
- */
-
-#include "BOP_Interface.h"
-#include "BSP_CSGMesh_CFIterator.h"
-
-#include <carve/csg_triangulator.hpp>
-#include <carve/interpolator.hpp>
-#include <carve/rescale.hpp>
-
-#include <iostream>
-
-using namespace carve::mesh;
-using namespace carve::geom;
-typedef unsigned int uint;
-
-#define MAX(x,y) ((x)>(y)?(x):(y))
-#define MIN(x,y) ((x)<(y)?(x):(y))
-
-static bool isQuadPlanar(carve::geom3d::Vector &v1, carve::geom3d::Vector &v2,
-                         carve::geom3d::Vector &v3, carve::geom3d::Vector &v4)
-{
-	carve::geom3d::Vector vec1, vec2, vec3, cross;
-
-	vec1 = v2 - v1;
-	vec2 = v4 - v1;
-	vec3 = v3 - v1;
-
-	cross = carve::geom::cross(vec1, vec2);
-
-	float production = carve::geom::dot(cross, vec3);
-	float magnitude = 1e-6 * cross.length();
-
-	return fabs(production) < magnitude;
-}
-
-static bool isFacePlanar(CSG_IFace &face, std::vector<carve::geom3d::Vector> &vertices)
-{
-	if (face.vertex_number == 4) {
-		return isQuadPlanar(vertices[face.vertex_index[0]], vertices[face.vertex_index[1]],
-		                    vertices[face.vertex_index[2]], vertices[face.vertex_index[3]]);
-	}
-
-	return true;
-}
-
-static void Carve_copyMeshes(std::vector<MeshSet<3>::mesh_t*> &meshes, std::vector<MeshSet<3>::mesh_t*> &new_meshes)
-{
-	std::vector<MeshSet<3>::mesh_t*>::iterator it = meshes.begin();
-
-	for(; it!=meshes.end(); it++) {
-		MeshSet<3>::mesh_t *mesh = *it;
-		MeshSet<3>::mesh_t *new_mesh = new MeshSet<3>::mesh_t(mesh->faces);
-
-		new_meshes.push_back(new_mesh);
-	}
-}
-
-static MeshSet<3> *Carve_meshSetFromMeshes(std::vector<MeshSet<3>::mesh_t*> &meshes)
-{
-	std::vector<MeshSet<3>::mesh_t*> new_meshes;
-
-	Carve_copyMeshes(meshes, new_meshes);
-
-	return new MeshSet<3>(new_meshes);
-}
-
-static MeshSet<3> *Carve_meshSetFromTwoMeshes(std::vector<MeshSet<3>::mesh_t*> &left_meshes,
-                                              std::vector<MeshSet<3>::mesh_t*> &right_meshes)
-{
-	std::vector<MeshSet<3>::mesh_t*> new_meshes;
-
-	Carve_copyMeshes(left_meshes, new_meshes);
-	Carve_copyMeshes(right_meshes, new_meshes);
-
-	return new MeshSet<3>(new_meshes);
-}
-
-static bool Carve_checkEdgeFaceIntersections_do(carve::csg::Intersections &intersections,
-                                                MeshSet<3>::face_t *face_a, MeshSet<3>::edge_t *edge_b)
-{
-	if(intersections.intersects(edge_b, face_a))
-		return true;
-
-	carve::mesh::MeshSet<3>::vertex_t::vector_t _p;
-	if(face_a->simpleLineSegmentIntersection(carve::geom3d::LineSegment(edge_b->v1()->v, edge_b->v2()->v), _p))
-		return true;
-
-	return false;
-}
-
-static bool Carve_checkEdgeFaceIntersections(carve::csg::Intersections &intersections,
-                                             MeshSet<3>::face_t *face_a, MeshSet<3>::face_t *face_b)
-{
-	MeshSet<3>::edge_t *edge_b;
-
-	edge_b = face_b->edge;
-	do {
-		if(Carve_checkEdgeFaceIntersections_do(intersections, face_a, edge_b))
-			return true;
-		edge_b = edge_b->next;
-	} while (edge_b != face_b->edge);
-
-	return false;
-}
-
-static inline bool Carve_facesAreCoplanar(const MeshSet<3>::face_t *a, const MeshSet<3>::face_t *b)
-{
-  carve::geom3d::Ray temp;
-  // XXX: Find a better definition. This may be a source of problems
-  // if floating point inaccuracies cause an incorrect answer.
-  return !carve::geom3d::planeIntersection(a->plane, b->plane, temp);
-}
-
-static bool Carve_checkMeshSetInterseciton_do(carve::csg::Intersections &intersections,
-                                              const RTreeNode<3, Face<3> *> *a_node,
-                                              const RTreeNode<3, Face<3> *> *b_node,
-                                              bool descend_a = true)
-{
-	if(!a_node->bbox.intersects(b_node->bbox))
-		return false;
-
-	if(a_node->child && (descend_a || !b_node->child)) {
-		for(RTreeNode<3, Face<3> *> *node = a_node->child; node; node = node->sibling) {
-			if(Carve_checkMeshSetInterseciton_do(intersections, node, b_node, false))
-				return true;
-		}
-	}
-	else if(b_node->child) {
-		for(RTreeNode<3, Face<3> *> *node = b_node->child; node; node = node->sibling) {
-			if(Carve_checkMeshSetInterseciton_do(intersections, a_node, node, true))
-				return true;
-		}
-	}
-	else {
-		for(size_t i = 0; i < a_node->data.size(); ++i) {
-			MeshSet<3>::face_t *fa = a_node->data[i];
-			aabb<3> aabb_a = fa->getAABB();
-			if(aabb_a.maxAxisSeparation(b_node->bbox) > carve::EPSILON) continue;
-
-			for(size_t j = 0; j < b_node->data.size(); ++j) {
-				MeshSet<3>::face_t *fb = b_node->data[j];
-				aabb<3> aabb_b = fb->getAABB();
-				if(aabb_b.maxAxisSeparation(aabb_a) > carve::EPSILON) continue;
-
-				std::pair<double, double> a_ra = fa->rangeInDirection(fa->plane.N, fa->edge->vert->v);
-				std::pair<double, double> b_ra = fb->rangeInDirection(fa->plane.N, fa->edge->vert->v);
-				if(carve::rangeSeparation(a_ra, b_ra) > carve::EPSILON) continue;
-
-				std::pair<double, double> a_rb = fa->rangeInDirection(fb->plane.N, fb->edge->vert->v);
-				std::pair<double, double> b_rb = fb->rangeInDirection(fb->plane.N, fb->edge->vert->v);
-				if(carve::rangeSeparation(a_rb, b_rb) > carve::EPSILON) continue;
-
-				if(!Carve_facesAreCoplanar(fa, fb)) {
-					if(Carve_checkEdgeFaceIntersections(intersections, fa, fb)) {
-						return true;
-					}
-				}
-			}
-		}
-	}
-
-	return false;
-}
-
-static bool Carve_checkMeshSetInterseciton(RTreeNode<3, Face<3> *> *rtree_a, RTreeNode<3, Face<3> *> *rtree_b)
-{
-	carve::csg::Intersections intersections;
-
-	return Carve_checkMeshSetInterseciton_do(intersections, rtree_a, rtree_b);
-}
-
-static void Carve_getIntersectedOperandMeshes(std::vector<MeshSet<3>::mesh_t*> &meshes, MeshSet<3>::aabb_t &otherAABB,
-                                              std::vector<MeshSet<3>::mesh_t*> &operandMeshes)
-{
-	std::vector<MeshSet<3>::mesh_t*>::iterator it = meshes.begin();
-	std::vector< RTreeNode<3, Face<3> *> *> meshRTree;
-
-	while(it != meshes.end()) {
-		MeshSet<3>::mesh_t *mesh = *it;
-		bool isAdded = false;
-
-		RTreeNode<3, Face<3> *> *rtree = RTreeNode<3, Face<3> *>::construct_STR(mesh->faces.begin(), mesh->faces.end(), 4, 4);
-
-		if (rtree->bbox.intersects(otherAABB)) {
-			bool isIntersect = false;
-
-			std::vector<MeshSet<3>::mesh_t*>::iterator operand_it = operandMeshes.begin();
-			std::vector<RTreeNode<3, Face<3> *> *>::iterator tree_it = meshRTree.begin();
-			for(; operand_it!=operandMeshes.end(); operand_it++, tree_it++) {
-				RTreeNode<3, Face<3> *> *operandRTree = *tree_it;
-
-				if(Carve_checkMeshSetInterseciton(rtree, operandRTree)) {
-					isIntersect = true;
-					break;
-				}
-			}
-
-			if(!isIntersect) {
-				operandMeshes.push_back(mesh);
-				meshRTree.push_back(rtree);
-
-				it = meshes.erase(it);
-				isAdded = true;
-			}
-		}
-
-		if (!isAdded) {
-			delete rtree;
-			it++;
-		}
-	}
-
-	std::vector<RTreeNode<3, Face<3> *> *>::iterator tree_it = meshRTree.begin();
-	for(; tree_it != meshRTree.end(); tree_it++) {
-		delete *tree_it;
-	}
-}
-
-static MeshSet<3> *Carve_getIntersectedOperand(std::vector<MeshSet<3>::mesh_t*> &meshes, MeshSet<3>::aabb_t &otherAABB)
-{
-	std::vector<MeshSet<3>::mesh_t*> operandMeshes;
-	Carve_getIntersectedOperandMeshes(meshes, otherAABB, operandMeshes);
-
-	if (operandMeshes.size() == 0)
-		return NULL;
-
-	return Carve_meshSetFromMeshes(operandMeshes);
-}
-
-static MeshSet<3> *Carve_unionIntersectingMeshes(MeshSet<3> *poly,
-                                                 MeshSet<3>::aabb_t &otherAABB,
-                                                 carve::interpolate::FaceAttr<uint> &oface_num)
-{
-	if(poly->meshes.size()<=1)
-		return poly;
-
-	carve::csg::CSG csg;
-
-	oface_num.installHooks(csg);
-	csg.hooks.registerHook(new carve::csg::CarveTriangulator, carve::csg::CSG::Hooks::PROCESS_OUTPUT_FACE_BIT);
-
-	std::vector<MeshSet<3>::mesh_t*> orig_meshes =
-			std::vector<MeshSet<3>::mesh_t*>(poly->meshes.begin(), poly->meshes.end());
-
-	MeshSet<3> *left = Carve_getIntersectedOperand(orig_meshes, otherAABB);
-
-	if (!left) {
-		/* no maniforlds which intersects another object at all */
-		return poly;
-	}
-
-	while(orig_meshes.size()) {
-		MeshSet<3> *right = Carve_getIntersectedOperand(orig_meshes, otherAABB);
-
-		if (!right) {
-			/* no more intersecting manifolds which intersects other object */
-			break;
-		}
-
-		try {
-			if(left->meshes.size()==0) {
-				delete left;
-
-				left = right;
-			}
-			else {
-				MeshSet<3> *result = csg.compute(left, right, carve::csg::CSG::UNION, NULL, carve::csg::CSG::CLASSIFY_EDGE);
-
-				delete left;
-				delete right;
-
-				left = result;
-			}
-		}
-		catch(carve::exception e) {
-			std::cerr << "CSG failed, exception " << e.str() << std::endl;
-
-			MeshSet<3> *result = Carve_meshSetFromTwoMeshes(left->meshes, right->meshes);
-
-			delete left;
-			delete right;
-
-			left = result;
-		}
-		catch(...) {
-			delete left;
-			delete right;
-
-			throw "Unknown error in Carve library";
-		}
-	}
-
-	/* append all meshes which doesn't have intersection with another operand as-is */
-	if (orig_meshes.size()) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list