Skip to content
Snippets Groups Projects
Commit 2fec543b authored by Daniel Schramm's avatar Daniel Schramm
Browse files

Variable render modes of drawable feature points

parent 47cfea01
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,11 @@ public class DrawableFeaturePoints extends Drawable {
*/
private final Map<Integer, Double> specialSizes = new HashMap<>();
/**
* feature points rendered differently than the default render mode
*/
private final Map<Integer, Integer> specialRenderModes = new HashMap<>();
/**
* Constructor.
*
......@@ -145,6 +150,65 @@ public class DrawableFeaturePoints extends Drawable {
public void resetAllSizesToDefault() {
specialSizes.clear();
}
/**
* Returns render mode of the feature point.
*
* @param index Index of the feature point
* @return The render mode or {@code null}
*/
public Integer getRenderMode(int index) {
if (index < 0 || index >= featurePoints.size()) {
return null;
}
if (specialRenderModes.containsKey(index)) {
return specialRenderModes.get(index);
} else {
return getRenderMode();
}
}
/**
* Sets render mode of the feature point.
* The render mode must be {@link GL2#GL_FILL}, {@link GL2#GL_LINE}
* or {@link GL2#GL_POINT}.
*
* @param index Index of the feature point
* @param renderMode New render mode of the feature point
* @throws IllegalArgumentException if renderMode isn't {@code GL_FILL},
* {@code GL_LINE} or {@code GL_POINT}
*/
public void setRenderMode(int index, int renderMode) {
if (renderMode != GL2.GL_FILL &&
renderMode != GL2.GL_LINE &&
renderMode != GL2.GL_POINT) {
throw new IllegalArgumentException("renderMode");
}
if (index < 0 || index >= featurePoints.size()) {
return;
}
if (renderMode == getRenderMode()) {
specialRenderModes.remove(index);
} else {
specialRenderModes.put(index, renderMode);
}
}
/**
* Removes (possible) special render mode of the feature point.
*
* @param index Index of the feature point
*/
public void resetRenderModeToDefault(int index) {
setRenderMode(index, getRenderMode());
}
/**
* Removes all individual render modes of feature points.
*/
public void resetAllRenderModesToDefault() {
specialRenderModes.clear();
}
@Override
protected void renderObject(GL2 gl) {
......@@ -158,12 +222,18 @@ public class DrawableFeaturePoints extends Drawable {
for (int i = 0; i < featurePoints.size(); i++) {
FeaturePoint fp = featurePoints.get(i);
Color specialColor = specialColors.get(i);
if (specialColor != null) {
float[] tmpRGB = {specialColor.getRed() / 255f, specialColor.getGreen() / 255f, specialColor.getBlue() / 255f, getTransparency()};
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, tmpRGB, 0);
}
Integer specialRenderMode = specialRenderModes.get(i);
if (specialRenderMode != null) {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, specialRenderMode);
}
gl.glPushMatrix();
gl.glTranslated(fp.getX(), fp.getY(), fp.getZ());
GLUquadric center = GLU_CONTEXT.gluNewQuadric();
......@@ -177,6 +247,9 @@ public class DrawableFeaturePoints extends Drawable {
if (specialColor != null) {
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, rgba, 0); // set default color
}
if (specialRenderMode != null) {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, getRenderMode()); // set default render mode
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment