Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Analyst WebApp
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fidentis
Analyst WebApp
Commits
1ac45cd4
There was an error fetching the commit references. Please try again later.
Commit
1ac45cd4
authored
4 years ago
by
Radek Ošlejšek
Browse files
Options
Downloads
Patches
Plain Diff
BoundingBox made immutable + fix
parent
b47a413c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/BoundingBox.java
+31
-44
31 additions, 44 deletions
.../main/java/cz/fidentis/analyst/mesh/core/BoundingBox.java
with
31 additions
and
44 deletions
MeshModel/src/main/java/cz/fidentis/analyst/mesh/core/BoundingBox.java
+
31
−
44
View file @
1ac45cd4
...
...
@@ -4,34 +4,50 @@ import java.util.List;
import
javax.vecmath.Vector3d
;
/**
* @author Natália Bebjaková
*
* Represent min-max box.
* It is automatically maintained by given point array of the model.
* @author Natalia Bebjakova
*
* 3D bounding box (cube) of <code>MeshPoint</code>s.
*/
public
class
BoundingBox
{
private
MeshPoint
maxPoint
;
private
MeshPoint
minPoint
;
private
MeshPoint
midPoint
;
private
double
maxDiag
;
private
final
MeshPoint
maxPoint
;
private
final
MeshPoint
minPoint
;
private
final
MeshPoint
midPoint
;
private
final
double
maxDiag
;
/**
* Creates bounding box
that is automatically maintained with respect to given array
.
* @param points
array of
points, must not be null or
p
empty
* Creates bounding box
from given mesh points
.
* @param points
List of mesh
points, must not be null or empty
* @throws IllegalArgumentException if the @code{points} param is null or empty
*/
public
BoundingBox
(
List
<
MeshPoint
>
points
)
{
if
(
points
==
null
||
points
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"points"
);
}
this
.
computeMinMax
(
points
);
this
.
computeMidDiag
();
minPoint
=
new
MeshPointImpl
(
new
Vector3d
(
Double
.
POSITIVE_INFINITY
,
Double
.
POSITIVE_INFINITY
,
Double
.
POSITIVE_INFINITY
),
null
,
null
);
maxPoint
=
new
MeshPointImpl
(
new
Vector3d
(
Double
.
NEGATIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
),
null
,
null
);
for
(
int
i
=
0
;
i
<
points
.
size
();
i
++)
{
MeshPoint
point
=
points
.
get
(
i
);
minPoint
.
getPosition
().
x
=
Math
.
min
(
minPoint
.
getPosition
().
x
,
point
.
getPosition
().
x
);
minPoint
.
getPosition
().
y
=
Math
.
min
(
minPoint
.
getPosition
().
y
,
point
.
getPosition
().
y
);
minPoint
.
getPosition
().
z
=
Math
.
min
(
minPoint
.
getPosition
().
z
,
point
.
getPosition
().
z
);
maxPoint
.
getPosition
().
x
=
Math
.
max
(
maxPoint
.
getPosition
().
x
,
point
.
getPosition
().
x
);
maxPoint
.
getPosition
().
y
=
Math
.
max
(
maxPoint
.
getPosition
().
y
,
point
.
getPosition
().
y
);
maxPoint
.
getPosition
().
z
=
Math
.
max
(
maxPoint
.
getPosition
().
z
,
point
.
getPosition
().
z
);
}
midPoint
=
(
minPoint
.
addPosition
(
maxPoint
)).
multiplyPosition
(
0.5
);
MeshPoint
diag
=
maxPoint
.
subtractPosition
(
minPoint
);
this
.
maxDiag
=
diag
.
abs
();
}
/**
*
*
Return the upper-bound corner of the bounding cube
* @return max point of the bounding box
*/
public
MeshPoint
getMaxPoint
()
{
...
...
@@ -39,7 +55,7 @@ public class BoundingBox {
}
/**
*
*
Return centroid of the bounding cube.
* @return middle point of the bounding box
*/
public
MeshPoint
getMidPoint
()
{
...
...
@@ -47,7 +63,7 @@ public class BoundingBox {
}
/**
*
*
Return the lower-bound corner of the bounding cube
* @return min point of the bounding box
*/
public
MeshPoint
getMinPoint
()
{
...
...
@@ -62,35 +78,6 @@ public class BoundingBox {
return
maxDiag
;
}
/**
* Recomputes the BoundingBox from all points
*/
private
void
computeMinMax
(
List
<
MeshPoint
>
points
)
{
minPoint
=
new
MeshPointImpl
(
new
Vector3d
(
Double
.
MAX_VALUE
,
Double
.
MAX_VALUE
,
Double
.
MAX_VALUE
),
null
,
null
);
maxPoint
=
new
MeshPointImpl
(
new
Vector3d
(-
100000.0
,-
100000.0
,-
100000.0
),
null
,
null
);
for
(
int
i
=
0
;
i
<
points
.
size
();
i
++)
{
MeshPoint
point
=
points
.
get
(
i
);
minPoint
.
getPosition
().
x
=
Math
.
min
(
minPoint
.
getPosition
().
x
,
point
.
getPosition
().
x
);
minPoint
.
getPosition
().
y
=
Math
.
min
(
minPoint
.
getPosition
().
y
,
point
.
getPosition
().
y
);
minPoint
.
getPosition
().
z
=
Math
.
min
(
minPoint
.
getPosition
().
z
,
point
.
getPosition
().
z
);
maxPoint
.
getPosition
().
x
=
Math
.
max
(
maxPoint
.
getPosition
().
x
,
point
.
getPosition
().
x
);
maxPoint
.
getPosition
().
y
=
Math
.
max
(
maxPoint
.
getPosition
().
y
,
point
.
getPosition
().
y
);
maxPoint
.
getPosition
().
z
=
Math
.
max
(
maxPoint
.
getPosition
().
z
,
point
.
getPosition
().
z
);
}
}
/**
* Recompute mid-point and max diagonal length.
*/
private
void
computeMidDiag
()
{
midPoint
=
(
minPoint
.
addPosition
(
maxPoint
)).
multiplyPosition
(
0.5
);
MeshPoint
diag
=
maxPoint
.
subtractPosition
(
minPoint
);
this
.
maxDiag
=
diag
.
abs
();
}
/**
* Returns description of BoundignBox.
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment