[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30273] branches/soc-2010-rohith291991: u v parametrization partly working.
Rohith B V
rohith291991 at gmail.com
Tue Jul 13 17:52:32 CEST 2010
Revision: 30273
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30273
Author: rohith291991
Date: 2010-07-13 17:52:32 +0200 (Tue, 13 Jul 2010)
Log Message:
-----------
u v parametrization partly working. Some parts need fixing.
Modified Paths:
--------------
branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h
branches/soc-2010-rohith291991/source/blender/modifiers/intern/MOD_quadrangulate.c
Added Paths:
-----------
branches/soc-2010-rohith291991/intern/comiso/extern/uv.h
branches/soc-2010-rohith291991/intern/comiso/intern/uv.cpp
Removed Paths:
-------------
branches/soc-2010-rohith291991/intern/comiso/intern/micode.cpp
Modified: branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h 2010-07-13 15:20:35 UTC (rev 30272)
+++ branches/soc-2010-rohith291991/intern/comiso/extern/CMesh.h 2010-07-13 15:52:32 UTC (rev 30273)
@@ -38,6 +38,15 @@
typedef struct CEdge{
int faces[2];//Indices of all faces having this edge
+double uflux[2];//Flux of u through edge from face[0] to face[1]
+double vflux[2];//Flux of v through edge from face[0] to face[1]
+//Optimization variables
+int usign[2];
+int vsign[2];
+int uvar[2];
+int vvar[2];
+int tvar[2];
+int test[2];
double kappa;//Correction angle between two adjacent faces
int index; //Index of the edge
int p;// Period Jump for v1-v2. For v2-v1 it is -p
@@ -55,7 +64,9 @@
int flag; //Flag for various purposes
int numNeighbors; //Number of neighboring faces
int v[4];// Indices of vertices. v4 is -1 if it is a triangle
-double theta; // Angle that the principle direction field makes with the edge represented by v1-v2
+double theta; //Angle that the principle direction field makes with the edge represented by v1-v2
+double ut[3]; //Direction of u field
+double vt[3]; //Direction of v field
}CFace;
Added: branches/soc-2010-rohith291991/intern/comiso/extern/uv.h
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/extern/uv.h (rev 0)
+++ branches/soc-2010-rohith291991/intern/comiso/extern/uv.h 2010-07-13 15:52:32 UTC (rev 30273)
@@ -0,0 +1,16 @@
+#ifndef UV_H
+#define UV_H
+
+#include "CMesh.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void mi_quad_param(CMesh *mesh,double n_quads);
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
\ No newline at end of file
Deleted: branches/soc-2010-rohith291991/intern/comiso/intern/micode.cpp
===================================================================
--- branches/soc-2010-rohith291991/intern/comiso/intern/micode.cpp 2010-07-13 15:20:35 UTC (rev 30272)
+++ branches/soc-2010-rohith291991/intern/comiso/intern/micode.cpp 2010-07-13 15:52:32 UTC (rev 30273)
@@ -1,405 +0,0 @@
-/*void compute_rotated_uv_vars(//rotates variable indices
- int var, int rot, //u is 2*var, v is 2*var+1
- int &uvar, int &vvar, //rotated variable indices
- int &usign, int &vsign // states if the opposite of the variable has to be used
-) {
- usign = (rot==1||rot==2) ? -1 : 1 ;
- vsign = (rot==2||rot==3) ? -1 : 1 ;
- uvar = 2*var + rot%2 ;
- vvar = 2*var + (rot+1)%2 ;
-}
-
-void compute_edge_flux(Map* map, bool curl_correction = true) { //with optional curl correction
- //Input attributes
- MapFacetAttribute<Vector3d> facet_K1(map,"K") ;// u scalar field
- MapHalfedgeAttribute<int> rot(map,"ls") ;//the rotation transitions
-
- //Output attributes
- MapFacetAttribute<Vector3d> facet_K2(map,"facet_K2") ;//v scalar field
- MapHalfedgeAttribute<double> uflux(map,"uflux") ;//flux of u through half edge
- MapHalfedgeAttribute<double> vflux(map,"vflux") ;//flux of v through half edge
-
- //Optimization variable indices and signs
- MapHalfedgeAttribute<int> uvar(map) ;
- MapHalfedgeAttribute<int> vvar(map) ;
- MapHalfedgeAttribute<int> usign(map) ;
- MapHalfedgeAttribute<int> vsign(map) ;
-
- //Reset the fluxes
- FOR_EACH_HALFEDGE(Map,map,hi) {
- uflux[hi] = 0 ;
- vflux[hi] = 0 ;
- }
-
- //Compute facet_K2 and fluxes per half edge
- FOR_EACH_FACET(Map,map,fi) {
- //recover the edge vectors
- Map::Halfedge* hi = fi->halfedge() ;
-
- Point3d p[3] ;
- for(int i=0; i<3; ++i) {
- p[i] = hi->vertex()->point() ;
- hi = hi->next() ;
- }
-
- Vector3d e[3] ;
- for(int i=0; i<3; ++i)
- e[i] = p[i]-p[(i+2)%3] ;
-
- //compute facet_K2
- Vector3d normal = e[1]^e[0] ;
- normal.normalize() ;
- Vector3d ut = facet_K1[fi] ;
- Vector3d vt = normal^ut ;
- facet_K2[fi] = vt ;
-
- //compute the flux through each edge
- hi = fi->halfedge() ; //probably useless
- for(int i=0; i<3; ++i) {
- uflux[hi] = ut*e[i] ;
- vflux[hi] = vt*e[i] ;
- hi = hi->next() ;
- }
- }
-
- if(!curl_correction) return ;
- //Curl correction tries to ensure that the u fluxes on the edges of a facet
- //sum to 0. Intuitively, all the entering flux should also get out.
-
- //TODO Mainly untested and probably buggy
-
- //mean of the fluxes per edge
- int nvar = 0 ;
- FOR_EACH_HALFEDGE(Map,map,hi) {
- if(Utilz::is_resp(hi) && !hi->is_border_edge()) {
- //the fluxes wrt the facet of the responsible half edge
- double uf_in = uflux[hi] ;
- double vf_in = vflux[hi] ;
- //the fluxes wrt the opposite facet corrected with rotation
- int uvar_out, vvar_out, usign_out, vsign_out ;
- int rotation = (4-rot[hi]+2)%4 ; //+2 since at least the opposite edge
- compute_rotated_uv_vars(nvar,rotation,uvar_out,vvar_out,usign_out,vsign_out) ;
- //checks if u and v are switched (rotation of pi/2 or 3pi/2)
- bool swap = (uvar_out%2)==1 ;
- double uf_out = swap ? vflux[hi->opposite()] : uflux[hi->opposite()] ;
- double vf_out = swap ? uflux[hi->opposite()] : vflux[hi->opposite()] ;
- uf_out *= usign_out ;
- vf_out *= vsign_out ;
- //means
- uflux[hi] = 0.5*(uf_in+uf_out) ;
- vflux[hi] = 0.5*(vf_in+vf_out) ;
- //assign opposite
- uflux[hi->opposite()] = swap ? usign_out*vflux[hi] : usign_out*uflux[hi];
- vflux[hi->opposite()] = swap ? vsign_out*uflux[hi] : vsign_out*vflux[hi];
-
- //Assign variable indices
- uvar[hi] = 2*nvar ;
- vvar[hi] = 2*nvar+1 ;
- usign[hi] = 1 ;
- vsign[hi] = 1 ;
- uvar[hi->opposite()] = uvar_out ;
- vvar[hi->opposite()] = vvar_out ;
- usign[hi->opposite()] = usign_out ;
- vsign[hi->opposite()] = vsign_out ;
- ++nvar ;
- } else if(hi->opposite()->is_border()) {
- //no opposite value to average, just provide variable index
- uvar[hi] = 2*nvar ;
- vvar[hi] = 2*nvar+1 ;
- usign[hi] = 1 ;
- vsign[hi] = 1 ;
- ++nvar ;
- }
- }
-
- //Setup least square system
- gmm::col_matrix< gmm::wsvector< double > > A ;
- gmm::resize(A,2*nvar,2*nvar) ;
- std::vector<double> b(2*nvar,0) ;
-
- FOR_EACH_HALFEDGE(Map,map,hi) {
- //These equations state that the resulting flux has to match the initial one
- if(!hi->is_border()) {
- if( Utilz::is_resp(hi) || hi->is_border_edge()) {
- A(uvar[hi],uvar[hi]) += 1 ;
- A(vvar[hi],vvar[hi]) += 1 ;
-
- //no need to use the using, the flux is already rotated if necessary
- b[uvar[hi]] += uflux[hi] ;
- b[vvar[hi]] += vflux[hi] ;
- }
- }
- }
- FOR_EACH_FACET(Map,map,fi) {
- //These equations state that the resulting flux should be 0 on a closed curve
- Map::Halfedge* hi = fi->halfedge() ;
- Map::Halfedge* hj = fi->halfedge() ;
- do {
- do {
- //u equations
- A(uvar[hi],uvar[hj]) += usign[hi]*usign[hj] ;
- //v equations
- A(vvar[hi],vvar[hj]) += vsign[hi]*vsign[hj] ;
- } while(hj != fi->halfedge()) ;
- } while(hi != fi->halfedge()) ;
- //The rhs is 0 for these equations
- }
-
- //The matrix has to be compressed for this solver
- gmm::csc_matrix<double> Acsc ;
- gmm::copy(A,Acsc) ;
-
- COMISO::MISolver solver;
- std::vector<int> ids_to_round ;
- std::vector<double> x(2*nvar,0) ;
- solver.solve(Acsc, x, b, ids_to_round);
-
- //set the fluxes to the optimized version
- FOR_EACH_HALFEDGE(Map,map,hi) {
- if(!hi->is_border()) {
- uflux[hi] = usign[hi]*x[uvar[hi]] ;
- vflux[hi] = vsign[hi]*x[vvar[hi]] ;
- }
- }
-}
-
-void mi_quad_param(CMesh &mesh,double n_quads){
-
- //Old stuff
- //Map* map = surface();
- //PolygonalToTriangulatedSurfaceWarper warp(map);
- //warp.pre_process();
-
- //Old Stuff
- //MapEditor editor(map);
- //editor.split_all_tex_vertices();
-
- //get the period from surface area
-
- double surface_area=0;
- //TODO calculate actual area here: FOR_EACH_FACET(Map,map,fi) surface_area += Geom::facet_area(fi);
- double h = sqrt(surface_area/n_quads);
- double hh = h * h ;
-
-
- //Old Stuff
-
- //Attributes from previous computations:
- //MapFacetAttribute<Vector3d> facet_K1(map,"K") ;//desired u direction DONE
- //MapVertexAttribute<double> ind(map,"ind") ;//states if a vertex is a singularity DONE
- //MapHalfedgeAttribute<bool> seam(map,"trans") ;//indicates if an edge is in the cut graph DONE
- //MapHalfedgeAttribute<int> rot(map,"ls") ;//the rotation of the edge (0 if not on the cut graph) DONE
-
- // avoid flat triangles by perturbing point positions
-// MapVertexAttribute<Point3d> save_pos(map);
- FOR_EACH_VERTEX(Map,map,vi)save_pos[vi] = vi->point();
-
- FOR_EACH_FACET(Map,map,fi){
- Map::Halfedge* corner[3] = {fi->halfedge(),fi->halfedge()->next(),fi->halfedge()->prev()};
- Point3d O;
- Vector3d axis[3];
- TrglGradient tr_grd(
- corner[0]->vertex()->point(),
- corner[1]->vertex()->point(),
- corner[2]->vertex()->point());
- if (tr_grd.is_flat())
- fi->halfedge()->vertex()->set_point(fi->halfedge()->vertex()->point()+(h/30.)*Vector3d(rand()%10,rand()%10,rand()%10));
- }
-
- //Variables
-
- //integer variables
- std::vector<int> ids_to_round ;
-
- //Distribute vertex uv variables
- MapHalfedgeAttribute<int> vvar(map,"vvar") ;//variable index of the corresponding vertex
-
- //Duplicate the vertex according to the cut graph
- int nvar = 0 ;
-
- FOR_EACH_VERTEX(Map,map,vi) {
- bool singular = ogf_abs(ind[vi]) >= 1E-13 ;
- Map::Halfedge* hi = vi->halfedge() ;
- //go to the previous seam edge if any
- do {
- hi = hi->next_around_vertex() ;
- } while(!seam[hi] && hi != vi->halfedge() && !hi->is_border()) ;
-
- Map::Halfedge* start = hi ;
- if(singular) ids_to_round.push_back(2*nvar) ;
- if(singular) ids_to_round.push_back(2*nvar+1) ;
- //separate the vertex in different variables for each parametric position
- do {
- if((seam[hi] || hi->is_border()) && hi != start) {
- //we justed crossed a cut, different from the original one (if any)
- //the vertex must be duplicated
- ++nvar ;
- if(singular) ids_to_round.push_back(2*nvar) ;
- if(singular) ids_to_round.push_back(2*nvar+1) ;
- }
- vvar[hi] = nvar ;
- hi = hi->prev_around_vertex() ;
- }
- while(hi != start) ;
- ++nvar ;
- }
-
- //Distribute seam edge variables
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list