Blender V2.61 - r43446

subd_face.h

Go to the documentation of this file.
00001 /*
00002  * Original code in the public domain -- castanyo@yahoo.es
00003  * 
00004  * Modifications copyright (c) 2011, Blender Foundation.
00005  * All rights reserved.
00006  * 
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  * * Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * * Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * 
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00019  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00020  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef __SUBD_FACE_H__
00030 #define __SUBD_FACE_H__
00031 
00032 #include "subd_edge.h"
00033 #include "subd_mesh.h"
00034 
00035 CCL_NAMESPACE_BEGIN
00036 
00037 /* Subd Face */
00038 
00039 class SubdFace
00040 {
00041 public:
00042     int id;
00043     SubdEdge *edge;
00044 
00045     SubdFace(int id_)
00046     {
00047         id = id_;
00048         edge = NULL;
00049     }
00050 
00051     bool contains(SubdEdge *e)
00052     {
00053         for(EdgeIterator it(edges()); !it.isDone(); it.advance())
00054             if(it.current() == e)
00055                 return true;
00056 
00057         return false;
00058     }
00059 
00060     int num_edges()
00061     {
00062         int num = 0;
00063 
00064         for(EdgeIterator it(edges()); !it.isDone(); it.advance())
00065             num++;
00066 
00067         return num;
00068     }
00069 
00070     bool is_boundary()
00071     {
00072         for(EdgeIterator it(edges()); !it.isDone(); it.advance()) {
00073             SubdEdge *edge = it.current();
00074 
00075             if(edge->pair->face == NULL)
00076                 return true;
00077         }
00078 
00079         return false;
00080     }
00081     
00082     /* iterate over edges in clockwise order */
00083     class EdgeIterator
00084     {
00085     public:
00086         EdgeIterator(SubdEdge *e) : end(NULL), cur(e) { }
00087 
00088         virtual void advance()
00089         {
00090             if (end == NULL) end = cur;
00091             cur = cur->next;
00092         }
00093 
00094         virtual bool isDone() { return end == cur; }
00095         virtual SubdEdge *current() { return cur; }
00096 
00097     private:
00098         SubdEdge *end;
00099         SubdEdge *cur;
00100     };
00101 
00102     EdgeIterator edges() { return EdgeIterator(edge); }
00103     EdgeIterator edges(SubdEdge *edge) {  return EdgeIterator(edge);  }
00104 };
00105 
00106 CCL_NAMESPACE_END
00107 
00108 #endif /* __SUBD_FACE_H__ */
00109