[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30983] branches/soc-2010-rohith291991/ intern/comiso/intern: Added code for automatic constraint generation.

Rohith B V rohith291991 at gmail.com
Mon Aug 2 16:25:19 CEST 2010


Revision: 30983
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30983
Author:   rohith291991
Date:     2010-08-02 16:25:19 +0200 (Mon, 02 Aug 2010)

Log Message:
-----------
Added code for automatic constraint generation. This has to be adapted.

Added Paths:
-----------
    branches/soc-2010-rohith291991/intern/comiso/intern/map_curvature.cpp
    branches/soc-2010-rohith291991/intern/comiso/intern/map_curvature.h

Added: branches/soc-2010-rohith291991/intern/comiso/intern/map_curvature.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/map_curvature.cpp	                        (rev 0)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/map_curvature.cpp	2010-08-02 14:25:19 UTC (rev 30983)
@@ -0,0 +1,335 @@
+/*
+ *  OGF/Graphite: Geometry and Graphics Programming Library + Utilities
+ *  Copyright (C) 2000-2003 Bruno Levy
+ *
+ *  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 bein 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  If you modify this software, you should include a notice giving the
+ *  name of the person performing the modification, the date of modification,
+ *  and the reason for such modification.
+ *
+ *  Contact: Bruno Levy
+ *
+ *     levy at loria.fr
+ *
+ *     ISA Project
+ *     LORIA, INRIA Lorraine, 
+ *     Campus Scientifique, BP 239
+ *     54506 VANDOEUVRE LES NANCY CEDEX 
+ *     FRANCE
+ *
+ *  Note that the GNU General Public License does not permit incorporating
+ *  the Software into proprietary programs. 
+ */
+/*
+#include "common.h"
+#include "map_curvature.h"
+//TODO
+//#include <OGF/cells/map/geometry.h>
+#include "normal_cycle.h"
+//#include <OGF/basic/debug/progress.h>
+
+#include <set>
+#include <stack>
+
+namespace OGF {
+
+    MapCurvature::MapCurvature() : mesh_(mesh),  radius_(0.001) { 
+        anisotropic_ = false ;
+        nb_anisotropic_iters_ = 3 ;
+        anisotropic_factor_ = 1.5 ;
+    }    
+
+    void MapCurvature::compute_curvature_tensor() {
+        double a = 1.0 / (3.1415926 * radius_*radius_) ;
+      //  ProgressLogger progress(map_->size_of_vertices()) ;
+		for(int i=0;i<mesh_.numVerts;i++)
+			{
+           
+          
+            NormalCycle ncycle ;
+            if(radius_ > 0) {
+                if(anisotropic_) {
+                    compute_curvature_tensor_anisotropic(
+                        i,radius_,nb_anisotropic_iters_,anisotropic_factor_,ncycle) ; 
+                } else {
+                    compute_curvature_tensor(i,radius_,ncycle) ;
+                }
+            } else {
+                std::cerr << "one ring" << std::endl ;
+                compute_curvature_tensor_one_ring(i, ncycle) ;
+            }
+
+            
+                mesh_.Kmin_[i] = a* ncycle.kmin() * ncycle.Kmin() ;
+            
+
+        
+                mesh_.Kmax_[i] = a * ncycle.kmax() * ncycle.Kmax() ;
+           
+
+           
+                mesh_.N_[i] =  a * ncycle.n() * ncycle.N() ;
+       
+
+          
+                mesh_.kmin_[i] = ncycle.kmin() ;
+            
+
+         
+                mesh_.kmax_[i] = ncycle.kmax() ;
+        
+           
+                mesh_.n_[i] = ncycle.n() ;
+            
+        }
+    }
+
+    void MapCurvature::compute_curvature_tensor_on_facets() {
+        double a = (radius_ > 0.0) ? (1.0 / (3.1415926 * radius_*radius_)) : 1.0 ;
+//        MapFacetAttribute<Vector3d> Kmin(map_, "K1") ;
+ //       MapFacetAttribute<Vector3d> Kmax(map_, "K2") ;
+        //ProgressLogger progress(map_->size_of_facets()) ;
+        for(int i=0;i<mesh_.numFaces;i++) {
+         
+            NormalCycle ncycle ;
+            compute_curvature_tensor(i,radius_,ncycle) ;
+            mesh_.Kmin[i] = a * ncycle.kmin() * ncycle.Kmin() ;
+            mesh_.Kmax[i] = a * ncycle.kmax() * ncycle.Kmax() ;
+           
+        }
+    }
+
+    static inline double angle(Map::Halfedge* h) {
+        Vector3d e  = Geom::vector(h) ;
+        Vector3d n1 = Geom::facet_normal(h->facet()) ;
+        Vector3d n2 = Geom::facet_normal(h->opposite()->facet()) ;
+        double sine = (n1 ^ n2) * e / e.norm() ;
+        if(sine >= 1.0) {
+            return 3.1415926 / 2.0 ;
+        }
+        if(sine <= -1.0) {
+            return -3.1415926 / 2.0 ;
+        }
+        return ::asin(sine) ;
+    }
+
+    void MapCurvature::compute_curvature_tensor(
+        Map::Facet* start, double radius, NormalCycle& nc
+    ) {
+        nc.begin() ;
+        std::set<Map::Vertex*> vertices ;
+        Point3d O = Geom::facet_barycenter(start) ;
+        std::stack<Map::Vertex*> S ;
+
+        Map::Halfedge* h = start->halfedge() ;
+        do {
+            if(!h->is_border_edge()) {
+                double beta = angle(h) ;
+                Vector3d V = Geom::vector(h->opposite()) ;
+                nc.accumulate_dihedral_angle(V, beta) ;
+            }
+            S.push(h->vertex()) ;
+            vertices.insert(h->vertex()) ;
+            h = h->next() ;
+        } while(h != start->halfedge()) ;
+
+        if(radius > 0.0) {
+            SphereNeighborhood neighborhood(O, radius) ;
+            while(!S.empty()) {
+                Map::Vertex* v = S.top() ;
+                S.pop() ;
+                const Point3d& P = v->point() ;
+                Map::Halfedge* h = v->halfedge() ;
+                do {
+                    Vector3d V = Geom::vector(h->opposite()) ;
+                    {
+                        bool isect = neighborhood.clip_vector(P, V) ;
+                        if(!h->is_border_edge()) {
+                            double beta = angle(h) ;
+                            nc.accumulate_dihedral_angle(V, beta) ;
+                        }
+                        if(!isect) {
+                            Map::Vertex* w = h->opposite()->vertex() ;
+                            if(vertices.find(w) == vertices.end()) {
+                                vertices.insert(w) ;
+                                S.push(w) ;
+                            }
+                        }
+                    }
+                    h = h->next_around_vertex() ;
+                } while(h != v->halfedge()) ;
+            }
+        }
+        nc.end() ;
+    }
+
+
+    void MapCurvature::compute_curvature_tensor(
+        Map::Vertex* start, double radius, NormalCycle& nc
+    ) {
+        nc.begin() ;
+        std::set<Map::Vertex*> vertices ;
+        const Point3d& O = start->point() ;
+        std::stack<Map::Vertex*> S ;
+        S.push(start) ;
+        vertices.insert(start) ;
+        SphereNeighborhood neighborhood(O, radius) ;
+        while(!S.empty()) {
+            Map::Vertex* v = S.top() ;
+            S.pop() ;
+            const Point3d& P = v->point() ;
+            Map::Halfedge* h = v->halfedge() ;
+            do {
+                Vector3d V = Geom::vector(h->opposite()) ;
+                if((v == start) || V * (P - O) > 0.0) {
+                    bool isect = neighborhood.clip_vector(P, V) ;
+                    if(!h->is_border_edge()) {
+                        double beta = angle(h) ;
+                        nc.accumulate_dihedral_angle(V, beta) ;
+                    }
+                    if(!isect) {
+                        Map::Vertex* w = h->opposite()->vertex() ;
+                        if(vertices.find(w) == vertices.end()) {
+                            vertices.insert(w) ;
+                            S.push(w) ;
+                        }
+                    }
+                }
+                h = h->next_around_vertex() ;
+            } while(h != v->halfedge()) ;
+        }
+        nc.end() ;
+    }
+
+
+
+    void MapCurvature::compute_curvature_tensor_anisotropic(
+        Map::Vertex* start, 
+        double initial_radius, int nb_iter, double expansion_factor,
+        NormalCycle& nc,
+        std::vector<Map::Vertex*>* vertices_in,
+        std::vector<CylinderNeighborhood>* neighborhoods_in 
+    ) {
+
+        MapTexVertexNormal normal(map_) ;
+
+        nc.begin() ;
+
+        std::set<Map::Vertex*> vertices ;
+        const Point3d& O = start->point() ;
+        std::stack<Map::Vertex*> S ;
+        S.push(start) ;
+        vertices.insert(start) ;
+        SphereNeighborhood neighborhood(O, initial_radius) ;
+        while(!S.empty()) {
+            Map::Vertex* v = S.top() ;
+            S.pop() ;
+            const Point3d& P = v->point() ;
+            Map::Halfedge* h = v->halfedge() ;
+            do {
+                Vector3d V = Geom::vector(h->opposite()) ;
+                if((v == start) || V * (P - O) > 0.0) {
+                    bool isect = neighborhood.clip_vector(P, V) ;
+                    if(!h->is_border_edge()) {
+                        double beta = angle(h) ;
+                        nc.accumulate_dihedral_angle(V, beta) ;
+                    }
+                    Map::Vertex* w = h->opposite()->vertex() ;
+                    if(vertices.find(w) == vertices.end()) {
+                        vertices.insert(w) ;
+                        if(!isect) {
+                            S.push(w) ;
+                        }
+                    }
+                }
+                h = h->next_around_vertex() ;
+            } while(h != v->halfedge()) ;
+        }
+        nc.end() ;
+
+
+        double radius = initial_radius ;
+        for(int iter=0; iter<nb_iter; iter++) {
+            radius *= expansion_factor ;
+//            Vector3d N = normal[start->halfedge()->tex_vertex()] ;
+            Vector3d N = nc.N() ;
+            double l = ogf_max(::fabs(nc.kmin()), ::fabs(nc.kmax())) ;
+            Vector3d K1 = (radius * nc.kmax() / l ) * nc.Kmax() ;
+            Vector3d K2 = (radius * nc.kmin() / l ) * nc.Kmin() ;
+            CylinderNeighborhood neighborhood(O, K1, K2, N) ;
+            if(neighborhoods_in != nil) {
+                neighborhoods_in->push_back(neighborhood) ;
+            }
+
+            vertices.clear() ;
+            S.push(start) ;
+            vertices.insert(start) ;
+
+            nc.begin() ;
+
+            while(!S.empty()) {
+                Map::Vertex* v = S.top() ;
+                if(vertices_in != nil && (iter == nb_iter - 1)) {
+                    vertices_in->push_back(v) ;
+                }
+                S.pop() ;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list