6 #include <dtkLog/dtkLog.h>
7 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
10 class axlShapeBSplineConverterPrivate
17 QMap< QPair<int, int>,
int> isOnEdge;
18 QMap< QPair<int, int>,
int> isOnFace;
20 int nonInteriorEdgeIndices;
22 QList<QString> labelsVertices;
23 QList<QString> labelsLines;
24 QList<QString> labelsTriangles;
29 d->shape_spline = NULL;
40 d->shape_spline = axlData;
41 d->nonInteriorEdgeIndices = d->shape_spline->countBoundaryEdges();
49 bool axlShapeBSplineConverter::isContained(
axlMesh *mesh){
64 int patch_count = d->shape_spline->countFaces();
65 qDebug() <<
"Number of patches" << d->shape_spline->countFaces();
68 qlonglong point_counter = 0;
69 qlonglong n_u_tot = 0;
70 qlonglong n_v_tot = 0;
72 for (qlonglong p_idx = 0; p_idx < patch_count; ++p_idx) {
75 double start_u = d->shape_spline->startParam_u(p_idx);
76 double start_v = d->shape_spline->startParam_v(p_idx);
77 double end_u = d->shape_spline->endParam_u(p_idx);
78 double end_v = d->shape_spline->endParam_v(p_idx);
80 double n_u = d->shape_spline->numSamples_u(p_idx);
81 double n_v = d->shape_spline->numSamples_v(p_idx);
83 double interval_u = (double)(end_u - start_u) / (n_u - 1);
84 double interval_v = (double)(end_v - start_v) / (n_v - 1);
85 double current_param_u = start_u;
86 double current_param_v = start_v;
90 for (
int j = 0; j < n_v; ++j) {
91 for (
int i = 0; i < n_u; ++i) {
93 d->shape_spline->eval(current_point, current_param_u, current_param_v, p_idx);
96 if (!( ((j == 0)) && (0 < p_idx) && (p_idx < patch_count) ))
99 qDebug() << point_counter << current_point;
102 current_param_u += interval_u;
104 current_param_u = start_u;
105 current_param_v += interval_v;
112 qlonglong patch_begin_idx = 0;
114 for (qlonglong p_idx = 0; p_idx < patch_count; ++p_idx) {
116 qDebug() <<
"Meshing patch" << p_idx;
117 int n_u = d->shape_spline->numSamples_u(p_idx);
118 int n_v = d->shape_spline->numSamples_v(p_idx);
123 for (
int j = 0; j < n_v - 1; ++j) {
124 for (
int i = 0; i < n_u - 1; ++i) {
125 int idx_1 = j * n_u + i + patch_begin_idx;
126 int idx_2 = idx_1 + 1;
127 int idx_3 = idx_1 + n_u;
128 int idx_4 = idx_3 + 1;
130 qDebug() <<
"idx_1" << idx_1;
132 QVector<int> first_triangle;
133 QVector<int> second_triangle;
135 first_triangle.push_back(s + idx_1);
136 first_triangle.push_back(s + idx_2);
137 first_triangle.push_back(s + idx_3);
139 second_triangle.push_back(s + idx_3);
140 second_triangle.push_back(s + idx_2);
141 second_triangle.push_back(s + idx_4);
148 patch_begin_idx += (n_u)*(n_v) - n_u;
150 qDebug() <<
"Finished meshing";
186 return "axlShapeBSplineConverter";
190 return QStringList();
194 return "axlShapeBSplineConverter";
199 return dtkAbstractDataFactory::instance()->registerDataConverterType(
"axlShapeBSplineConverter", QStringList(),
"axlMesh",
createaxlShapeBSplineConverter);
202 int axlShapeBSplineConverter::isInterior(
int i,
int n_u,
int n_v){
204 if(i < n_u || i%n_u == 0 || i >= (n_v-1)*(n_u) || i%n_u == (n_u-1))
210 QPair<int,int > axlShapeBSplineConverter::whatEdge(
int numFace,
int i,
int n_u,
int n_v){
213 return QPair<int,int>(d->shape_spline->getFace(numFace)->edgesIndices.first(), i);
214 }
else if (i >= (n_v-1)*(n_u)) {
215 return QPair<int,int>(d->shape_spline->getFace(numFace)->edgesIndices.last(), (i%((n_v-1)*(n_u))));
216 }
else if (i%n_u == 0 ){
217 return QPair<int,int>(d->shape_spline->getFace(numFace)->edgesIndices.at(1), i/n_u);
219 return QPair<int,int>(d->shape_spline->getFace(numFace)->edgesIndices.at(2), (i+1)/n_u -1);
223 void axlShapeBSplineConverter::insertEdge(
axlMesh *mesh,
int numEdge){
226 int count = d->output->vertex_count();
227 int n = d->shape_spline->getEdge(numEdge)->support->numSamples();
230 for (
int i = 1; i < (n-1); i++) {
231 d->output->push_back_vertex(mesh->
vertex2(i,point));
232 d->labelsVertices.append(d->shape_spline->getEdge(numEdge)->tag);
233 d->isOnEdge.insert(QPair<int,int>(numEdge,i), i-1 + count);
239 if (numEdge < d->nonInteriorEdgeIndices) {
241 for (
int i = 0; i < mesh->
edge_count(); i++) {
243 int f = d->isOnEdge.value(QPair<int,int>(numEdge,mesh->
edge(i).first()));
244 int s = d->isOnEdge.value(QPair<int,int>(numEdge,mesh->
edge(i).last()));
246 d->output->push_back_edge(f,s);
247 d->labelsLines.append(d->shape_spline->getEdge(numEdge)->tag);
252 void axlShapeBSplineConverter::insertFace(
axlMesh *mesh,
int numFace){
254 int count = d->output->vertex_count();
255 int nu = d->shape_spline->getFace(numFace)->support->numSamples_u();
256 int nv = d->shape_spline->getFace(numFace)->support->numSamples_v();
260 for (
int j = 1; j < nv-1; j++) {
261 for (
int i = 1; i < nu-1; i++) {
263 d->output->push_back_vertex(mesh->
vertex2(ind, point));
264 d->labelsVertices.append(
"interior");
265 d->isOnFace.insert(QPair<int,int>(numFace,ind), count);
274 for (
int i = 0; i < mesh->
face_count(); i++) {
276 int formerf = mesh->
face(i).first();
277 int formers = mesh->
face(i).at(1);
278 int formert = mesh->
face(i).last();
284 if (isInterior(formerf,nu,nv)) {
285 f = d->isOnFace.value(QPair<int,int>(numFace, formerf));
287 QPair<int,int > numEdge = whatEdge(numFace, formerf, nu, nv);
288 f = d->isOnEdge.value(numEdge);
291 if (isInterior(formers,nu,nv)) {
292 s = d->isOnFace.value(QPair<int,int>(numFace, formers));
294 QPair<int,int > numEdge = whatEdge(numFace, formers, nu, nv);
295 s = d->isOnEdge.value(numEdge);
298 if (isInterior(formert,nu,nv)) {
299 t = d->isOnFace.value(QPair<int,int>(numFace, formert));
301 QPair<int,int > numEdge = whatEdge(numFace, formert, nu, nv);
302 t = d->isOnEdge.value(numEdge);
305 d->output->push_back_face(f, s, t);
306 d->labelsTriangles.append(
"interior");
312 return d->labelsVertices;
314 return d->labelsLines;
316 return d->labelsTriangles;
Class axlPoint defines 3D points.
int face_count(void) const
QStringList fromTypes(void) const
QString toType(void) const
~axlShapeBSplineConverter()
void setData(dtkAbstractData *data)
int edge_count(void) const
QList< QString > getLabels(int i)
dtkAbstractDataConverter * createaxlShapeBSplineConverter(void)
axlPoint * vertex2(int ind, axlPoint *point) const
Set vertex values of vertices with index ind and return it.
static bool registered(void)
void push_back_face(const Face &face)
axlShapeBSplineConverter()
Class axlShapeBSpline defines a set of boundary curves (Edges) and bspline surface patches (Face)...
QString description(void) const
int vertex_count(void) const
Class axlMesh defines a piecewise-linear 3D object.
void push_back_vertex(const double &x, const double &y, const double &z)
Add a new vertex to the mesh.