Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

triangle.h

00001 //
00002 // triangle.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _math_isosurf_triangle_h
00029 #define _math_isosurf_triangle_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <math/isosurf/tricoef.h>
00036 #include <math/isosurf/edge.h>
00037 
00038 class Triangle: public RefCount {
00039   protected:
00040     // these break gcc 2.5.8
00041     //unsigned int _order:5;
00042     //unsigned int _orientation0:1;
00043     //unsigned int _orientation1:1;
00044     //unsigned int _orientation2:1;
00045     //unsigned char _order;
00046     //unsigned char _orientation0;
00047     //unsigned char _orientation1;
00048     //unsigned char _orientation2;
00049     unsigned int _order;
00050     unsigned int _orientation0;
00051     unsigned int _orientation1;
00052     unsigned int _orientation2;
00053     Ref<Edge> _edges[3];
00054     Ref<Vertex> *_vertices;
00055   public:
00056     enum {max_order = 10};
00057 
00058     Triangle(const Ref<Edge>& v1, const Ref<Edge>& v2, const Ref<Edge>& v3,
00059              unsigned int orient0 = 0);
00060     Ref<Edge> edge(int i) { return _edges[i]; };
00061     int contains(const Ref<Edge>&) const;
00062     unsigned int orientation(int i) const
00063     {
00064       return i==0?_orientation0:i==1?_orientation1:_orientation2;
00065     }
00066     unsigned int orientation(const Ref<Edge>&) const;
00067     ~Triangle();
00068     void add_edges(AVLSet<Ref<Edge> >&);
00069     void add_vertices(AVLSet<Ref<Vertex> >&);
00070 
00071     // returns the surface area element
00072     // 0<=r<=1, 0<=s<=1, 0<=r+s<=1
00073     // Ref<Vertex> is the intepolated vertex (both point and normal)
00074     void interpolate(const Ref<TriInterpCoef>&,
00075                      double r,double s,const Ref<Vertex>&v, SCVector3& dA);
00076     void interpolate(double r,double s,const Ref<Vertex>&v, SCVector3& dA);
00077     void interpolate(double r,double s,const Ref<Vertex>&v, SCVector3& dA,
00078                      const Ref<Volume> &vol, double isovalue);
00079 
00080     // returns a corner vertex from the triangle
00081     // i = 0 is the (0,0) vertex (or L1 = 1, L2 = 0, L3 = 0)
00082     // i = 1 is the (r=1,s=0) vertex (or L1 = 0, L2 = 1, L3 = 0)
00083     // i = 2 is the (r=0,s=1) vertex (or L1 = 0, L2 = 0, L3 = 1)
00084     Ref<Vertex> vertex(int i);
00085 
00086     double flat_area();
00087 
00088     // flip the orientation
00089     void flip();
00090 
00091     unsigned int order() const { return _order; }
00092 
00093     void set_order(int order, const Ref<Volume>&vol,double isovalue);
00094 };
00095 
00096 
00097 
00098 class TriangleIntegrator: public DescribedClass {
00099   private:
00100     int _n;
00101     double* _r;
00102     double* _s;
00103     double* _w;
00104     // precomputed interpolation coefficients for triangles of various orders
00105     Ref<TriInterpCoef> **coef_; // max_order by _n
00106   protected:
00107     void set_r(int i,double r);
00108     void set_s(int i,double s);
00109     void set_w(int i,double w);
00110     void init_coef();
00111     void clear_coef();
00112   public:
00113     TriangleIntegrator(const Ref<KeyVal>&);
00114     TriangleIntegrator(int n);
00115     virtual ~TriangleIntegrator();
00116     inline double w(int i) { return _w[i]; }
00117     inline double r(int i) { return _r[i]; }
00118     inline double s(int i) { return _s[i]; }
00119     inline int n() { return _n; }
00120     virtual void set_n(int n);
00121     Ref<TriInterpCoef> coef(int order, int i) { return coef_[order-1][i]; }
00122 };
00123 
00124 
00125 class GaussTriangleIntegrator: public TriangleIntegrator {
00126   private:
00127     void init_rw(int order);
00128   public:
00129     GaussTriangleIntegrator(const Ref<KeyVal>&);
00130     GaussTriangleIntegrator(int order);
00131     ~GaussTriangleIntegrator();
00132     void set_n(int n);
00133 };
00134 
00135 #endif
00136 
00137 // Local Variables:
00138 // mode: c++
00139 // c-file-style: "CLJ"
00140 // End:

Generated at Thu Oct 4 18:08:48 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.