JavaCAD
SubdividedPointArray.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates.
3  * All rights reserved. Use is subject to license terms.
4  *
5  * This file is available and licensed under the following license:
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * - Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * - Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the distribution.
16  * - Neither the name of Oracle Corporation nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 package eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.symbolic;
33 
34 import eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.SubdivisionMesh;
35 import java.util.Arrays;
36 
37 
38 // TODO: Auto-generated Javadoc
43 
45  private final float[] controlPoints; // points of the previous subdivision level
46 
48  private final int[][] controlInds; // indices corresponding to controlPoints
49 
51  private final float[][] controlFactors; // factors corresponding to controlPoints
52 
54  private final int[][] inds;
55 
57  private final float[][] factors;
58 
61 
63  private int currPoint = 0;
64 
73  super(new float[NUM_COMPONENTS_PER_POINT * numPoints]);
74 
75  this.controlPoints = controlPointArray.data;
76  this.controlInds = new int[numPoints][];
77  this.controlFactors = new float[numPoints][];
78  this.inds = new int[numPoints][];
79  this.factors = new float[numPoints][];
80 
82  }
83 
84 
91  public int addFacePoint(int[] vertices) {
92  controlInds[currPoint] = vertices;
93  controlFactors[currPoint] = new float[vertices.length];
94  Arrays.fill(controlFactors[currPoint], 1.0f/vertices.length);
95 
96  inds[currPoint] = new int[0];
97  factors[currPoint] = new float[0];
98 
99  return currPoint++;
100  }
101 
111  public int addEdgePoint(int[] facePoints, int fromPoint, int toPoint, boolean isBoundary) {
112  if (isBoundary) {
113  controlInds[currPoint] = new int[] {fromPoint, toPoint};
114  controlFactors[currPoint] = new float[] {0.5f, 0.5f};
115 
116  inds[currPoint] = new int[0];
117  factors[currPoint] = new float[0];
118  } else {
119  int n = facePoints.length + 2;
120  controlInds[currPoint] = new int[] {fromPoint, toPoint};
121  controlFactors[currPoint] = new float[] {1.0f/n, 1.0f/n};
122 
123  inds[currPoint] = facePoints;
124  factors[currPoint] = new float[facePoints.length];
125  Arrays.fill(factors[currPoint], 1.0f/n);
126  }
127  return currPoint++;
128  }
129 
143  public int addControlPoint(int[] facePoints, int[] edgePoints, int[] fromEdgePoints, int[] toEdgePoints, boolean[] isEdgeBoundary, int origPoint, boolean isBoundary, boolean hasInternalEdge) {
144  if (isBoundary) {
145  if ((boundaryMode == SubdivisionMesh.BoundaryMode.CREASE_EDGES) || hasInternalEdge) {
146  controlInds[currPoint] = new int[] {origPoint};
147  controlFactors[currPoint] = new float[] {0.5f};
148 
149  int numBoundaryEdges = 0;
150  for (int i = 0; i < edgePoints.length; i++) {
151  if (isEdgeBoundary[i]) {
152  numBoundaryEdges++;
153  }
154  }
155  inds[currPoint] = new int[numBoundaryEdges];
156  factors[currPoint] = new float[numBoundaryEdges];
157  int boundaryEdgeInd = 0;
158  for (int i = 0; i < edgePoints.length; i++) {
159  if (isEdgeBoundary[i]) {
160  inds[currPoint][boundaryEdgeInd] = edgePoints[i];
161  factors[currPoint][boundaryEdgeInd] = 0.25f;
162  boundaryEdgeInd++;
163  }
164  }
165  } else {
166  controlInds[currPoint] = new int[] {origPoint};
167  controlFactors[currPoint] = new float[] {1.0f};
168 
169  inds[currPoint] = new int[0];
170  factors[currPoint] = new float[0];
171  }
172  } else {
173  int n = facePoints.length;
174 
175  controlInds[currPoint] = new int[1 + edgePoints.length*2];
176  controlFactors[currPoint] = new float[1 + edgePoints.length*2];
177  controlInds[currPoint][0] = origPoint;
178  controlFactors[currPoint][0] = (n - 3.0f) / n;
179  for (int i = 0; i < edgePoints.length; i++) {
180  controlInds[currPoint][1+2*i] = fromEdgePoints[i];
181  controlFactors[currPoint][1+2*i] = 1.0f/(n * n);
182  controlInds[currPoint][1+2*i+1] = toEdgePoints[i];
183  controlFactors[currPoint][1+2*i+1] = 1.0f/(n * n);
184  }
185 
186  inds[currPoint] = facePoints;
187  factors[currPoint] = new float[facePoints.length];
188  Arrays.fill(factors[currPoint], 1.0f/(n * n));
189  }
190  return currPoint++;
191  }
192 
193  /* (non-Javadoc)
194  * @see eu.mihosoft.vrl.v3d.ext.openjfx.shape3d.symbolic.SymbolicPointArray#update()
195  */
196  @Override
197  public void update() {
198  int ci;
199  float f;
200  float x, y, z;
201  for (int i = 0; i < numPoints; i++) {
202  x = y = z = 0.0f;
203  for (int j = 0; j < controlInds[i].length; j++) {
204  ci = 3 * controlInds[i][j];
205  f = controlFactors[i][j];
206  x += controlPoints[ci] * f;
207  y += controlPoints[ci + 1] * f;
208  z += controlPoints[ci + 2] * f;
209  }
210  for (int j = 0; j < inds[i].length; j++) {
211  ci = 3 * inds[i][j];
212  f = factors[i][j];
213  x += data[ci] * f;
214  y += data[ci + 1] * f;
215  z += data[ci + 2] * f;
216  }
217  data[3*i] = x;
218  data[3*i+1] = y;
219  data[3*i+2] = z;
220  }
221  }
222 }
int addEdgePoint(int[] facePoints, int fromPoint, int toPoint, boolean isBoundary)
int addControlPoint(int[] facePoints, int[] edgePoints, int[] fromEdgePoints, int[] toEdgePoints, boolean[] isEdgeBoundary, int origPoint, boolean isBoundary, boolean hasInternalEdge)
SubdividedPointArray(SymbolicPointArray controlPointArray, int numPoints, SubdivisionMesh.BoundaryMode boundaryMode)