[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37852] branches/soc-2011-avocado/blender: Improvement on autoseam recursive implementation.
shuvro sarker
shuvro05 at gmail.com
Mon Jun 27 10:08:58 CEST 2011
Revision: 37852
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37852
Author: shuvro
Date: 2011-06-27 08:08:56 +0000 (Mon, 27 Jun 2011)
Log Message:
-----------
Improvement on autoseam recursive implementation.
Modified Paths:
--------------
branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.h
branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp
branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h
branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp 2011-06-27 07:57:06 UTC (rev 37851)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.cpp 2011-06-27 08:08:56 UTC (rev 37852)
@@ -2,8 +2,9 @@
#include <stdio.h>
AutoseamAdjacency::AutoseamAdjacency(int dimension)
-{
+{
m_adjacency = MatrixXd::Zero(dimension, dimension);
+ m_index_map_vector.resize(dimension, -1);
}
void AutoseamAdjacency::set(int row, int col, float value)
@@ -17,9 +18,25 @@
int AutoseamAdjacency::get(int row, int col)
{
+ printf("num rows: %ld cols: %ld", m_adjacency.rows(), m_adjacency.cols());
+ printf("row: %d col: %d and the adjacency value is: %f",row, col, m_adjacency(row, col));
return m_adjacency(row, col) > 0.05 ? 1 : 0;
}
+void AutoseamAdjacency::set_map_default()
+{
+ int i;
+ int rows = m_adjacency.rows();
+ for(i = 0; i < rows; i++){
+ set_mapping(i, i);
+ }
+}
+float AutoseamAdjacency::get_value(int row, int col)
+{
+ return m_adjacency(row,col);
+}
+
+
AutoseamAdjacency::~AutoseamAdjacency()
{
clear_eigenspaces();
@@ -35,6 +52,29 @@
m_eigenspaces.clear();
}
+void AutoseamAdjacency::set_mapping(int index, int value)
+{
+ //m_index_map[index] = value;
+ m_index_map_vector[index] = value;
+}
+
+int AutoseamAdjacency::get_mapping(int index)
+{
+ if(m_index_map_vector[index] != -1){
+ return m_index_map_vector[index];
+ }
+ else{
+ printf("No value present for index %d\n", index);
+ return -1;
+ }
+}
+
+//int AutoseamAdjacency::is_adjacent(int index1, int index2)
+//{
+// //if the indexes are not adjacent it returns -1
+// return m_adjacency(index1, index1) ? 1 : -1;
+//}
+
bool AutoseamAdjacency::generate_seam()
{
MatrixXd& a = m_adjacency;
@@ -84,9 +124,36 @@
}
void AutoseamAdjacency::get_split(int n, int *fplus, unsigned int* nplus, int* fminus, unsigned int* nminus)
-{
- if(m_eigenspaces.size())
+{
+ int i;
+ int face_index;
+
+ if(m_eigenspaces.size()){
m_eigenspaces[n]->get(fplus, nplus, fminus, nminus);
+
+ /* pack the original indexes. */
+ for(i = 0; i < *nplus; i++){
+ face_index = get_mapping(fplus[i]);
+ if(face_index != -1){
+ fplus[i] = get_mapping(fplus[i]);
+ }
+ else{
+ printf("error in getting mapping. May be mapping is not done.\n");
+ }
+ }
+
+ for(i = 0; i < *nminus; i++){
+ face_index = get_mapping(fminus[i]);
+
+ if(face_index != -1){
+ fminus[i] = get_mapping(fminus[i]);
+ }
+ else{
+ printf("error in getting mapping. May be mapping is not done.\n");
+ }
+
+ }
+ }
else{
*nplus = 0;
*nminus = 0;
Modified: branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.h 2011-06-27 07:57:06 UTC (rev 37851)
+++ branches/soc-2011-avocado/blender/intern/autoseam/AutoseamAdjacency.h 2011-06-27 08:08:56 UTC (rev 37852)
@@ -4,7 +4,10 @@
#include "AutoseamUtility.h"
#include "AutoseamEigenspace.h"
#include <vector>
+//#include <map>
+//using namespace std;
+
class AutoseamAdjacency
{
public:
@@ -19,10 +22,17 @@
int get_num_splits();
int get_best_split();
void get_split(int n, int *fplus, unsigned int* nplus, int* fminus, unsigned int* nminus);
+ void set_mapping(int index, int value);
+ int get_mapping(int index);
+ void set_map_default();
+ //int is_adjacent(int index1, int index2);
+ float get_value(int row, int col);
private:
Eigen::MatrixXd m_adjacency;
std::vector<AutoseamEigenspace*> m_eigenspaces;
+ std::vector<int> m_index_map_vector;
+ //map<int,int> m_index_map;
};
Modified: branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp 2011-06-27 07:57:06 UTC (rev 37851)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.cpp 2011-06-27 08:08:56 UTC (rev 37852)
@@ -73,6 +73,33 @@
return adj->get(row, col);
}
+float autoseam_get_value(AUTOSEAM_Adjacency handle, int row, int col)
+{
+ AutoseamAdjacency *adj = reinterpret_cast<AutoseamAdjacency*>(handle);
+ return adj->get_value(row, col);
+}
+
+void autoseam_set_map_default(AUTOSEAM_Adjacency handle)
+{
+ AutoseamAdjacency *adj = reinterpret_cast<AutoseamAdjacency*>(handle);
+ return adj->set_map_default();
+}
+
+
+
+int autoseam_get_mapping(AUTOSEAM_Adjacency handle, int index)
+{
+ AutoseamAdjacency *adj = reinterpret_cast<AutoseamAdjacency*>(handle);
+ return adj->get_mapping(index);
+}
+
+void autoseam_set_mapping(AUTOSEAM_Adjacency handle, int index, int value)
+{
+ AutoseamAdjacency *adj = reinterpret_cast<AutoseamAdjacency*>(handle);
+ return adj->set_mapping(index, value);
+}
+
+
int autoseam_generate_seam(AUTOSEAM_Adjacency handle)
{
AutoseamAdjacency *adj = reinterpret_cast<AutoseamAdjacency*>(handle);
Modified: branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h 2011-06-27 07:57:06 UTC (rev 37851)
+++ branches/soc-2011-avocado/blender/intern/autoseam/autoseam_C_API.h 2011-06-27 08:08:56 UTC (rev 37852)
@@ -50,10 +50,15 @@
void autoseam_set_adjacent(AUTOSEAM_Adjacency handle, int row, int col, float value);
int autoseam_is_adjacent(AUTOSEAM_Adjacency handle, int row, int col);
+int autoseam_get_mapping(AUTOSEAM_Adjacency handle, int index);
+void autoseam_set_mapping(AUTOSEAM_Adjacency handle, int index, int value);
+
int autoseam_generate_seam(AUTOSEAM_Adjacency handle);
int autoseam_get_num_splits(AUTOSEAM_Adjacency handle);
int autoseam_get_best_split(AUTOSEAM_Adjacency handle);
void autoseam_get_split(AUTOSEAM_Adjacency handle, int n, int *fplus, unsigned int* nplus, int* fminus, unsigned int* nminus);
+float autoseam_get_value(AUTOSEAM_Adjacency handle, int row, int col);
+void autoseam_set_map_default(AUTOSEAM_Adjacency handle);
#ifdef __cplusplus
}
Modified: branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c
===================================================================
--- branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c 2011-06-27 07:57:06 UTC (rev 37851)
+++ branches/soc-2011-avocado/blender/source/blender/editors/mesh/autoseam_tools.c 2011-06-27 08:08:56 UTC (rev 37852)
@@ -57,6 +57,8 @@
#include "MEM_guardedalloc.h"
#include "WM_api.h"
+//#include "AutoseamAdjacency.h"
+
#define MAX_DEPTH 4
int get_sign(float number){
@@ -121,9 +123,12 @@
bSeam = find_index(idx2, fplus, nplus);
}
other_face=BMIter_Step(&face_iter);
+ printf("indexes are %d %d\n", idx1, idx2);
}
}
- if (bSeam) BM_SetHFlag(edge, BM_SEAM);
+ if (bSeam){
+ BM_SetHFlag(edge, BM_SEAM);
+ }
}
}
}
@@ -154,7 +159,7 @@
return -1;
}
-static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial, int num_faces, int *faces )
+static void autoseam_create_graph( AUTOSEAM_Adjacency adj, BMesh *bm, int combinatorial, int num_faces, int *faces, int set_mapping )
{
BMEdge *edge;
BMLoop *loop;
@@ -199,6 +204,7 @@
if(is_second_index == 1){
//printf("edge :%d %d", loop->f->head.index, loop->radial_next->f->head.index);
autoseam_set_adjacent(adj, loop->f->head.index, loop->radial_next->f->head.index, edge_length);
+
}
}
@@ -215,144 +221,245 @@
}
-static int recursion_depth = 0;
-
-int generate_seam_recursive(BMesh *bm, int *fplus_p, int nplus_p, int *fminus_p, int nminus_p)
+int generate_seam_recursive_v2(BMesh *bm, AUTOSEAM_Adjacency adj, int recursion_depth)
{
-
-
- AUTOSEAM_Adjacency adj;
- AUTOSEAM_Adjacency adj_second;
+ int s;
+ int i, j;
int num_faces;
- static int s, s2;
- int *fplus, *fminus;
- int *fplus2, *fminus2;
+ int *fplus, *fminus;
+ unsigned int nplus, nminus;
- int nplus = nplus_p;
- int nminus = nminus_p;
+ AUTOSEAM_Adjacency adj_plus;
+ AUTOSEAM_Adjacency adj_minus;
- int nplus2, nminus2;
+ if(!recursion_depth) {
+ autoseam_delete_adjacency(adj);
+ return 0;
+ }
- fplus = fplus_p;
- fminus = fminus_p;
-
+ autoseam_generate_seam(adj);
+ s = autoseam_get_best_split(adj);
num_faces = BM_Count_Element(bm, BM_FACE);
- while(recursion_depth < MAX_DEPTH)
- {
- if(!recursion_depth){
-
- adj = autoseam_create_adjacency(num_faces);
-
- autoseam_prepare_graph(bm);
- autoseam_create_graph(adj, bm, 1, -1, NULL);
- autoseam_generate_seam(adj);
-
- s = autoseam_get_best_split(adj);
-
- fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
- fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
-
- autoseam_get_split(adj, s, fplus, &nplus, fminus, &nminus);
-
- /* mark the seam on the mesh */
- autoseam_clear_seam(bm);
- autoseam_mark_seam(bm, fplus, nplus, fminus, nminus);
-
- autoseam_delete_adjacency(adj);
- recursion_depth++;
- generate_seam_recursive(bm,fplus, nplus, fminus, nminus);
-
+ /* allocate memory to store the F+ and F- arrays. */
+ fplus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fplus");
+ fminus = (int*)MEM_callocN(num_faces*sizeof(int), "autoseam_fminus");
+
+ /* This method should return the original indexes. */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list