2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
30 * Implementation of external api for CSG part of BSP lib interface.
33 #include "../extern/CSG_BooleanOps.h"
34 #include "BSP_CSGMesh_CFIterator.h"
35 #include "MEM_RefCountPtr.h"
37 #include "../../boolop/extern/BOP_Interface.h"
41 #include "BSP_MeshPrimitives.h"
44 BSP_CSGMesh *output_mesh;
49 CSG_BooleanOperation *
50 CSG_NewBooleanFunction(
53 BSP_MeshInfo * mesh_info = new BSP_MeshInfo;
54 CSG_BooleanOperation * output = new CSG_BooleanOperation;
56 if (mesh_info==NULL || output==NULL) return NULL;
58 mesh_info->output_mesh = NULL;
59 output->CSG_info = mesh_info;
65 * Compute the boolean operation, UNION, INTERSECION or DIFFERENCE
68 CSG_PerformBooleanOperation(
69 CSG_BooleanOperation *operation,
70 CSG_OperationType op_type,
71 CSG_FaceIteratorDescriptor obAFaces,
72 CSG_VertexIteratorDescriptor obAVertices,
73 CSG_FaceIteratorDescriptor obBFaces,
74 CSG_VertexIteratorDescriptor obBVertices
76 if (operation == NULL) return 0;
77 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info);
78 if (mesh_info == NULL) return 0;
80 obAFaces.Reset(obAFaces.it);
81 obBFaces.Reset(obBFaces.it);
82 obAVertices.Reset(obAVertices.it);
83 obBVertices.Reset(obBVertices.it);
91 case e_csg_difference:
92 boolType = BOP_DIFFERENCE;
95 boolType = BOP_INTERSECTION;
99 BoolOpState boolOpResult;
101 boolOpResult = BOP_performBooleanOperation( boolType,
102 (BSP_CSGMesh**) &(mesh_info->output_mesh),
103 obAFaces, obAVertices, obBFaces, obBVertices);
109 switch (boolOpResult) {
110 case BOP_OK: return 1;
111 case BOP_NO_SOLID: return -2;
112 case BOP_ERROR: return 0;
118 CSG_OutputFaceDescriptor(
119 CSG_BooleanOperation * operation,
120 CSG_FaceIteratorDescriptor * output
122 if (operation == NULL) return 0;
123 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info);
125 if (mesh_info == NULL) return 0;
126 if (mesh_info->output_mesh == NULL) return 0;
128 BSP_CSGMesh_FaceIt_Construct(mesh_info->output_mesh,output);
134 CSG_OutputVertexDescriptor(
135 CSG_BooleanOperation * operation,
136 CSG_VertexIteratorDescriptor *output
138 if (operation == NULL) return 0;
139 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info);
141 if (mesh_info == NULL) return 0;
142 if (mesh_info->output_mesh == NULL) return 0;
144 BSP_CSGMeshVertexIt_Construct(mesh_info->output_mesh,output);
149 CSG_FreeVertexDescriptor(
150 CSG_VertexIteratorDescriptor * v_descriptor
152 BSP_CSGMesh_VertexIt_Destruct(v_descriptor);
157 CSG_FreeFaceDescriptor(
158 CSG_FaceIteratorDescriptor * f_descriptor
160 BSP_CSGMesh_FaceIt_Destruct(f_descriptor);
165 CSG_FreeBooleanOperation(
166 CSG_BooleanOperation *operation
168 if (operation != NULL) {
169 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info);
171 delete (mesh_info->output_mesh);