yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #01046
[svn] r1697 - trunk/extra/SpherePadder
Author: richefeu
Date: 2009-02-26 13:52:04 +0100 (Thu, 26 Feb 2009)
New Revision: 1697
Added:
trunk/extra/SpherePadder/CellPartition.cpp
trunk/extra/SpherePadder/CellPartition.hpp
Log:
2 files that were forgotten
Added: trunk/extra/SpherePadder/CellPartition.cpp
===================================================================
--- trunk/extra/SpherePadder/CellPartition.cpp 2009-02-26 12:47:38 UTC (rev 1696)
+++ trunk/extra/SpherePadder/CellPartition.cpp 2009-02-26 12:52:04 UTC (rev 1697)
@@ -0,0 +1,135 @@
+/*************************************************************************
+* Copyright (C) 2009 by Jean Francois Jerier *
+* jerier@xxxxxxxxxxxxxxx *
+* Copyright (C) 2009 by Vincent Richefeu *
+* vincent.richefeu@xxxxxxxxxxx *
+* *
+* This program is free software; it is licensed under the terms of the *
+* GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+
+#include "CellPartition.hpp"
+
+CellPartition::CellPartition()
+{
+ cell_is_found = false;
+}
+
+void CellPartition::init(TetraMesh & mesh, double security_factor)
+{
+ if (!mesh.isOrganized)
+ {
+ cerr << "CellPartition::CellPartition, mesh is not valid!" << endl;
+ return;
+ }
+
+ xmin = xmax = mesh.node[0].x;
+ ymin = ymax = mesh.node[0].y;
+ zmin = zmax = mesh.node[0].z;
+ for (unsigned int i = 1 ; i < mesh.node.size() ; ++i)
+ {
+ xmin = (xmin > mesh.node[i].x) ? mesh.node[i].x : xmin;
+ xmax = (xmax < mesh.node[i].x) ? mesh.node[i].x : xmax;
+ ymin = (ymin > mesh.node[i].y) ? mesh.node[i].y : ymin;
+ ymax = (ymax < mesh.node[i].y) ? mesh.node[i].y : ymax;
+ zmin = (zmin > mesh.node[i].z) ? mesh.node[i].z : zmin;
+ zmax = (zmax < mesh.node[i].z) ? mesh.node[i].z : zmax;
+ }
+
+ isize = (unsigned int)((xmax - xmin) / mesh.mean_segment_length);
+ if (isize < 1) isize = 1;
+
+ jsize = (unsigned int)((ymax - ymin) / mesh.mean_segment_length);
+ if (jsize < 1) jsize = 1;
+
+ ksize = (unsigned int)((zmax - zmin) / mesh.mean_segment_length);
+ if (ksize < 1) ksize = 1;
+
+// isize *= security_factor;
+// jsize *= security_factor;
+// ksize *= security_factor;
+
+ //isize = jsize = ksize = 1; // pour test
+
+ cerr << "nb cells: " << isize << ", " << jsize << ", " << ksize << endl;
+
+ vector<unsigned int> kvec;
+ for (unsigned int k = 0 ; k < ksize ; ++k) kvec.push_back(0);
+ vector<vector<unsigned int> > jvec;
+ for (unsigned int j = 0 ; j < jsize ; ++j) jvec.push_back(kvec);
+ for (unsigned int i = 0 ; i < isize ; ++i) cellId.push_back(jvec);
+
+ Cell C;
+ unsigned int n = 0;
+ for (unsigned int i = 0 ; i < isize ; ++i)
+ {
+ for (unsigned int j = 0 ; j < jsize ; ++j)
+ {
+ for (unsigned int k = 0 ; k < ksize ; ++k)
+ {
+ cell.push_back(C);
+ cellId[i][j][k] = n++;
+ }
+ }
+ }
+
+ x_adjuster = (double)isize / (xmax - xmin);
+ y_adjuster = (double)jsize / (ymax - ymin);
+ z_adjuster = (double)ksize / (zmax - zmin);
+
+ cell_is_found = false;
+}
+
+void CellPartition::add(unsigned int n, double x, double y, double z)
+{
+ cell_is_found = false;
+
+ int i,j,k;
+ i = (int)(floor((x - xmin) * x_adjuster));
+ j = (int)(floor((y - ymin) * y_adjuster));
+ k = (int)(floor((z - zmin) * z_adjuster));
+
+ if (i >= (int)isize) current_i = isize - 1;
+ else if (i < 0) current_i = 0;
+ else current_i = (unsigned int)i;
+
+ if (j >= (int)jsize) current_j = jsize - 1;
+ else if (j < 0) current_j = 0;
+ else current_j = (unsigned int)j;
+
+ if (k >= (int)ksize) current_k = ksize - 1;
+ else if (k < 0) current_k = 0;
+ else current_k = (unsigned int)k;
+
+ cell[ cellId[current_i][current_j][current_k] ].sphereId.push_back(n);
+
+ cell_is_found = true;
+}
+
+
+void CellPartition::locateCellOf(double x, double y, double z)
+{
+ cell_is_found = false;
+
+ int i,j,k;
+
+ i = (int)(floor((x - xmin) * x_adjuster));
+ j = (int)(floor((y - ymin) * y_adjuster));
+ k = (int)(floor((z - zmin) * z_adjuster));
+
+ if (i >= (int)isize) current_i = isize - 1;
+ else if (i < 0) current_i = 0;
+ else current_i = (unsigned int)i;
+
+ if (j >= (int)jsize) current_j = jsize - 1;
+ else if (j < 0) current_j = 0;
+ else current_j = (unsigned int)j;
+
+ if (k >= (int)ksize) current_k = ksize - 1;
+ else if (k < 0) current_k = 0;
+ else current_k = (unsigned int)k;
+
+ cell_is_found = true;
+}
+
+
Added: trunk/extra/SpherePadder/CellPartition.hpp
===================================================================
--- trunk/extra/SpherePadder/CellPartition.hpp 2009-02-26 12:47:38 UTC (rev 1696)
+++ trunk/extra/SpherePadder/CellPartition.hpp 2009-02-26 12:52:04 UTC (rev 1697)
@@ -0,0 +1,60 @@
+/*************************************************************************
+* Copyright (C) 2009 by Jean Francois Jerier *
+* jerier@xxxxxxxxxxxxxxx *
+* Copyright (C) 2009 by Vincent Richefeu *
+* vincent.richefeu@xxxxxxxxxxx *
+* *
+* This program is free software; it is licensed under the terms of the *
+* GNU General Public License v2 or later. See file LICENSE for details. *
+*************************************************************************/
+
+#ifndef CELL_PARTITION_HPP
+#define CELL_PARTITION_HPP
+
+#include "TetraMesh.hpp"
+
+struct Cell
+{
+ vector<unsigned int> sphereId;
+};
+
+class CellPartition
+{
+ protected:
+
+ vector<vector<vector<unsigned int> > > cellId;
+ vector<Cell> cell;
+ Cell out_of_cells;
+ double xmin,xmax;
+ double ymin,ymax;
+ double zmin,zmax;
+
+ double x_adjuster,y_adjuster,z_adjuster;
+
+ public:
+
+ unsigned int isize,jsize,ksize;
+ unsigned int current_i,current_j,current_k;
+ bool cell_is_found; // TODO enlever
+
+ CellPartition();
+ void init(TetraMesh & mesh, double security_factor = 1.0);
+ void add(unsigned int n, double x, double y, double z);
+ void locateCellOf(double x, double y, double z);
+
+ Cell& get_cell (unsigned int i,unsigned int j,unsigned int k) { return cell[ cellId[i][j][k] ]; }
+ unsigned int get_cellId (unsigned int i,unsigned int j,unsigned int k) { return cellId[i][j][k]; }
+
+ unsigned int i_down() { return ( (current_i > 0) ? (current_i - 1) : 0 ); }
+ unsigned int i_up () { return ( (current_i < isize - 1) ? (current_i + 1) : isize - 1 ); }
+
+ unsigned int j_down() { return ( (current_j > 0) ? (current_j - 1) : 0 ); }
+ unsigned int j_up () { return ( (current_j < jsize - 1) ? (current_j + 1) : jsize - 1); }
+
+ unsigned int k_down() { return ( (current_k > 0) ? (current_k - 1) : 0 ); }
+ unsigned int k_up () { return ( (current_k < ksize - 1) ? (current_k + 1) : ksize - 1); }
+
+};
+
+#endif // CELL_PARTITION_HPP
+