Blender V2.61 - r43446
Classes | Typedefs | Enumerations | Functions

CSG_BooleanOps.h File Reference

Go to the source code of this file.

Classes

struct  CSG_IFace
struct  CSG_IVertex
struct  CSG_FaceIteratorDescriptor
struct  CSG_VertexIteratorDescriptor
struct  CSG_BooleanOperation

Typedefs

typedef void * CSG_IteratorPtr
typedef int(* CSG_FaceItDoneFunc )(CSG_IteratorPtr it)
typedef void(* CSG_FaceItFillFunc )(CSG_IteratorPtr it, CSG_IFace *face)
typedef void(* CSG_FaceItStepFunc )(CSG_IteratorPtr it)
typedef void(* CSG_FaceItResetFunc )(CSG_IteratorPtr it)
typedef struct
CSG_FaceIteratorDescriptor 
CSG_FaceIteratorDescriptor
typedef int(* CSG_VertexItDoneFunc )(CSG_IteratorPtr it)
typedef void(* CSG_VertexItFillFunc )(CSG_IteratorPtr it, CSG_IVertex *face)
typedef void(* CSG_VertexItStepFunc )(CSG_IteratorPtr it)
typedef void(* CSG_VertexItResetFunc )(CSG_IteratorPtr it)
typedef struct
CSG_VertexIteratorDescriptor 
CSG_VertexIteratorDescriptor

Enumerations

enum  CSG_OperationType { e_csg_union, e_csg_intersection, e_csg_difference, e_csg_classify }

Functions

CSG_BooleanOperationCSG_NewBooleanFunction (void)
int CSG_PerformBooleanOperation (CSG_BooleanOperation *operation, CSG_OperationType op_type, CSG_FaceIteratorDescriptor obAFaces, CSG_VertexIteratorDescriptor obAVertices, CSG_FaceIteratorDescriptor obBFaces, CSG_VertexIteratorDescriptor obBVertices)
int CSG_OutputFaceDescriptor (CSG_BooleanOperation *operation, CSG_FaceIteratorDescriptor *output)
int CSG_OutputVertexDescriptor (CSG_BooleanOperation *operation, CSG_VertexIteratorDescriptor *output)
void CSG_FreeVertexDescriptor (CSG_VertexIteratorDescriptor *v_descriptor)
void CSG_FreeFaceDescriptor (CSG_FaceIteratorDescriptor *f_descriptor)
void CSG_FreeBooleanOperation (CSG_BooleanOperation *operation)

Detailed Description

Definition in file CSG_BooleanOps.h.


Typedef Documentation

typedef int(* CSG_FaceItDoneFunc)(CSG_IteratorPtr it)

Definition at line 119 of file CSG_BooleanOps.h.

typedef void(* CSG_FaceItFillFunc)(CSG_IteratorPtr it, CSG_IFace *face)

Definition at line 120 of file CSG_BooleanOps.h.

typedef void(* CSG_FaceItResetFunc)(CSG_IteratorPtr it)

Definition at line 122 of file CSG_BooleanOps.h.

typedef void(* CSG_FaceItStepFunc)(CSG_IteratorPtr it)

Definition at line 121 of file CSG_BooleanOps.h.

typedef void* CSG_IteratorPtr

The actual useful data contained in a group of faces is described by the following struct

abstraction.

The CSG module asks blender to fill in an instance of the above structure, and requests blender to move up and down (iterate) through it's face and vertex containers.

An iterator supports the following functions. int IsDone(iterator *it) -- returns true if the iterator has reached the end of it's container.

void Fill(iterator *it,DataType *data) -- Return the contents of the container at the current iterator position.

void Step(iterator *it) -- increment the iterator to the next position in the container.

The iterator is used in the following manner.

MyIterator * iterator = ... DataType data;

while (!IsDone(iterator)) { Fill(iterator,&data); //process information pointed to by data ... Step(iterator); }

The CSG module does not want to know about the implementation of these functions so we use the c function ptr mechanism to hide them. Our iterator descriptor now looks like this.

Definition at line 117 of file CSG_BooleanOps.h.

Similarly to walk through the vertex arrays we have.

Definition at line 136 of file CSG_BooleanOps.h.

typedef void(* CSG_VertexItFillFunc)(CSG_IteratorPtr it, CSG_IVertex *face)

Definition at line 137 of file CSG_BooleanOps.h.

Definition at line 139 of file CSG_BooleanOps.h.

Definition at line 138 of file CSG_BooleanOps.h.


Enumeration Type Documentation

The actual iterator structures are not exposed to the CSG module, they will contain datatypes specific to blender.

Module interface functions.

The functions below are to be used in the following way:

// Create a boolean operation handle CSG_BooleanOperation *operation = CSG_NewBooleanFunction(); if (operation == NULL) { // deal with low memory exception }

// Report to the user if they will loose any data! ...

// Get some mesh iterators for your mesh data structures CSG_FaceIteratorDescriptor obA_faces = ... CSG_VertexIteratorDescriptor obA_verts = ...

// same for object B CSG_FaceIteratorDescriptor obB_faces = ... CSG_VertexIteratorDescriptor obB_verts = ...

// perform the operation...!

int success = CSG_PerformBooleanOperation( operation, e_csg_intersection, obA_faces, obA_vertices, obB_faces, obB_vertices );

// if the operation failes report miserable faiulre to user // and clear up data structures. if (!success) { ... CSG_FreeBooleanOperation(operation); return; }

// read the new mesh vertices back from the module // and assign to your own mesh structure.

// First we need to create a CSG_IVertex so the module can fill it in. CSG_IVertex vertex; CSG_VertexIteratorDescriptor * verts_it = CSG_OutputVertexDescriptor(operation);

// initialize your vertex container with the number of verts (verts_it->num_elements)

while (!verts_it->Done(verts_it->it)) { verts_it->Fill(verts_it->it,&vertex);

// create a new vertex of your own type and add it // to your mesh structure. verts_it->Step(verts_it->it); } // Free the vertex iterator CSG_FreeVertexDescriptor(verts_it);

// similarly for faces. CSG_IFace face;

// you may need to reserve some memory in face->user_data here.

// initialize your face container with the number of faces (faces_it->num_elements)

CSG_FaceIteratorDescriptor * faces_it = CSG_OutputFaceDescriptor(operation);

while (!faces_it->Done(faces_it->it)) { faces_it->Fill(faces_it->it,&face);

// create a new face of your own type and add it // to your mesh structure. faces_it->Step(&faces_it->it); }

// Free the face iterator CSG_FreeVertexDescriptor(faces_it);

// that's it free the operation.

CSG_FreeBooleanOperation(operation); return; Description of boolean operation type.

Enumerator:
e_csg_union 
e_csg_intersection 
e_csg_difference 
e_csg_classify 

Definition at line 246 of file CSG_BooleanOps.h.


Function Documentation

void CSG_FreeBooleanOperation ( CSG_BooleanOperation operation)

Free the memory associated with a boolean operation. NOTE any iterator descriptor describing the output will become invalid after this call and should be freed immediately.

Definition at line 170 of file CSG_BooleanOps.cpp.

References CSG_BooleanOperation::CSG_info, NULL, and BSP_MeshInfo::output_mesh.

Referenced by NewBooleanDerivedMesh_intern().

void CSG_FreeFaceDescriptor ( CSG_FaceIteratorDescriptor f_descriptor)

Definition at line 162 of file CSG_BooleanOps.cpp.

References BSP_CSGMesh_FaceIt_Destruct().

Referenced by NewBooleanDerivedMesh_intern().

void CSG_FreeVertexDescriptor ( CSG_VertexIteratorDescriptor v_descriptor)

Clean up functions. Free internal memory associated with CSG interface structures. You must call these functions on any structures created by the module, even if subsequent operations did not succeed.

Definition at line 154 of file CSG_BooleanOps.cpp.

References BSP_CSGMesh_VertexIt_Destruct().

Referenced by NewBooleanDerivedMesh_intern().

CSG_BooleanOperation* CSG_NewBooleanFunction ( void  )

Return a ptr to a CSG_BooleanOperation object allocated on the heap. The CSG module owns the memory associated with the returned ptr, use CSG_FreeBooleanOperation() to free this memory.

Definition at line 55 of file CSG_BooleanOps.cpp.

References CSG_BooleanOperation::CSG_info, NULL, and BSP_MeshInfo::output_mesh.

Referenced by NewBooleanDerivedMesh_intern().

int CSG_OutputFaceDescriptor ( CSG_BooleanOperation operation,
CSG_FaceIteratorDescriptor output 
)

If the a boolean operation was successful, you may access the results through the following functions.

CSG_OuputFaceDescriptor() returns a ptr to a CSG_FaceIteratorDesciptor allocated on the heap and owned by the CSG module. The iterator is positioned at the start of the internal face container. CSG_OutputVertexDescriptor() returns a ptr to a CSG_VertexIteratorDescriptor allocated on the heap and owned by the CSG module. The iterator is positioned at the start of the internal vertex container. There is no function to rewind an iterator but you may obtain more than one iterator at a time. Please use the function CSG_FreeFaceIterator() and CSG_FreeVertexIterator to free internal memory allocated for these iterators.

If the last operation was not successful, these functions return NULL.

Definition at line 123 of file CSG_BooleanOps.cpp.

References BSP_CSGMesh_FaceIt_Construct(), CSG_BooleanOperation::CSG_info, NULL, and BSP_MeshInfo::output_mesh.

Referenced by NewBooleanDerivedMesh_intern().

int CSG_OutputVertexDescriptor ( CSG_BooleanOperation operation,
CSG_VertexIteratorDescriptor output 
)
int CSG_PerformBooleanOperation ( CSG_BooleanOperation operation,
CSG_OperationType  op_type,
CSG_FaceIteratorDescriptor  obAFaces,
CSG_VertexIteratorDescriptor  obAVertices,
CSG_FaceIteratorDescriptor  obBFaces,
CSG_VertexIteratorDescriptor  obBVertices 
)

Attempt to perform a boolean operation between the 2 objects of the desired type. This may fail due to an internal error or lack of memory. In this case 0 is returned, otehrwise 1 is returned indicating success.

Parameters:
operationis a 'handle' into the CSG_Module created by CSG_NewBooleanFunction()
op_typeis the operation to perform.
obAFacesis an iterator over the faces of objectA,
obAVerticesis an iterator over the vertices of objectA
obAFacesis an iterator over the faces of objectB,
obAVerticesis an iterator over the vertices of objectB
interp_functhe face_vertex data interpolation function.(see above)

All iterators must be valid and pointing to the first element in their respective containers.

Compute the boolean operation, UNION, INTERSECION or DIFFERENCE

Definition at line 73 of file CSG_BooleanOps.cpp.

References BOP_DIFFERENCE, BOP_ERROR, BOP_INTERSECTION, BOP_NO_SOLID, BOP_OK, BOP_performBooleanOperation(), BOP_UNION, CSG_BooleanOperation::CSG_info, e_csg_difference, e_csg_union, CSG_FaceIteratorDescriptor::it, CSG_VertexIteratorDescriptor::it, NULL, BSP_MeshInfo::output_mesh, CSG_VertexIteratorDescriptor::Reset, and CSG_FaceIteratorDescriptor::Reset.

Referenced by NewBooleanDerivedMesh_intern().