Skip to content

Commit

Permalink
Linux offline screen fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrkioraskari committed Aug 19, 2020
1 parent 5df838e commit 8fc000c
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 193 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mvdXML Checker
v2.40
v2.41

![General View](https://raw.githubusercontent.com/jyrkioraskari/OnlineMvdXMLChecker/master/doc/mvdXMLAPI.png)

Expand Down
2 changes: 1 addition & 1 deletion mvdXMLChecker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<module>../mvdXMLCheckerCommon</module>
<module>../mvdXMLCommandLineChecker</module>
</modules>
<version>2.40</version>
<version>2.41</version>
</project>
2 changes: 2 additions & 0 deletions mvdXMLChecker/target/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/classes/
/test-classes/
2 changes: 1 addition & 1 deletion mvdXMLCheckerCommon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@
</plugin>
</plugins>
</build>
<version>2.40</version>
<version>2.41</version>
</project>
313 changes: 160 additions & 153 deletions mvdXMLCheckerCommon/src/main/java/org/opensource_bimserver/bcf/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import javax.xml.bind.Marshaller;

import org.bimserver.plugins.renderengine.RenderEngineException;
import org.bimserver.plugins.renderengine.RenderEngineGeometry;
import org.bimserver.plugins.renderengine.RenderEngineInstance;
import org.ifcopenshell.IfcGeomServerClientEntity;
import org.ifcopenshell.IfcOpenShellEntityInstance;
import org.ifcopenshell.IfcOpenShellModel;
Expand Down Expand Up @@ -90,9 +88,9 @@ public UUID getUuid() {
}

public void write(ZipOutputStream zipOutputStream) throws IOException, BcfException {
ZipEntry markup_dir = new ZipEntry(getUuid().toString() + "/"); // JO 2020 added empty directory to be inline with the standard
ZipEntry markup_dir = new ZipEntry(getUuid().toString() + "/"); // JO 2020 added empty directory to be inline with the standard
zipOutputStream.putNextEntry(markup_dir);

ZipEntry markup = new ZipEntry(getUuid().toString() + "/markup.bcf");
zipOutputStream.putNextEntry(markup);
try {
Expand Down Expand Up @@ -126,7 +124,6 @@ private void createDummySnapshot(ZipOutputStream zipOutputStream) throws IOExcep
int width = 500, height = 500;
BufferedImage bi = makeImage(width, height); // new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
// paint(ig2);
try {
ImageIO.write(bi, "PNG", zipOutputStream);
} catch (IOException e) {
Expand All @@ -141,161 +138,171 @@ private void paint(Graphics g) {
Font font = new Font("Serif", Font.PLAIN, 32);
g2.setColor(Color.RED);
g2.setFont(font);
g2.drawString("To be done", 50, 70);
g2.drawString("Not in Linux", 50, 70);
}

public BufferedImage makeImage(int width, int height) {
GLU glu = new GLU();
GLProfile gl_profile = GLProfile.getDefault();
GLCapabilities capabilities = new GLCapabilities(gl_profile);
capabilities.setOnscreen(false);

GLDrawableFactory factory = GLDrawableFactory.getFactory(gl_profile);
GLOffscreenAutoDrawable drawable = factory.createOffscreenAutoDrawable(null, capabilities, null, width, height);
drawable.display();
drawable.getContext().makeCurrent();

GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
System.out.println("this.renderEngineModel.isPresent(): "+this.renderEngineModel.isPresent());
if (this.renderEngineModel.isPresent()) {

IfcOpenShellEntityInstance renderEngineInstance;
try {
renderEngineInstance = this.renderEngineModel.get().getInstanceFromExpressId(ifcProductExpressId.get().intValue());
if (renderEngineInstance != null) {
IfcGeomServerClientEntity geometry = renderEngineInstance.generateGeometry();
if (geometry != null && geometry.getIndices().length > 0) {

double xmax = Float.MIN_VALUE;
double ymax = Float.MIN_VALUE;
double zmax = Float.MIN_VALUE;
double xmin = Float.MAX_VALUE;
double ymin = Float.MAX_VALUE;
double zmin = Float.MAX_VALUE;

int[] indices = geometry.getIndices();
float[] vertices=geometry.getPositions();
for (int i = 0; i < indices.length; i = i + 3) {
double x1 = vertices[indices[i] * 3];
double y1 = vertices[indices[i] * 3 + 1];
double z1 = vertices[indices[i] * 3 + 2];
double x2 = vertices[indices[i + 1] * 3];
double y2 = vertices[indices[i + 1] * 3 + 1];
double z2 = vertices[indices[i + 1] * 3 + 2];
double x3 = vertices[indices[i + 2] * 3];
double y3 = vertices[indices[i + 2] * 3 + 1];
double z3 = vertices[indices[i + 2] * 3 + 2];

if (x1 < xmin)
xmin = x1;
if (x2 < xmin)
xmin = x2;
if (x3 < xmin)
xmin = x3;

if (x1 > xmax)
xmax = x1;
if (x2 > xmax)
xmax = x2;
if (x3 > xmax)
xmax = x3;

if (y1 < ymin)
ymin = y1;
if (y2 < ymin)
ymin = y2;
if (y3 < ymin)
ymin = y3;

if (y1 > ymax)
ymax = y1;
if (y2 > ymax)
ymax = y2;
if (y3 > ymax)
ymax = y3;

if (z1 < zmin)
zmin = z1;
if (z2 < zmin)
zmin = z2;
if (z3 < zmin)
zmin = z3;

if (z1 > zmax)
zmax = z1;
if (z2 > zmax)
zmax = z2;
if (z3 > zmax)
zmax = z3;
}
double xscale = xmax - xmin;
double yscale = ymax - ymin;
double zscale = zmax - zmin;

double xmean = xmax - xscale / 2;
double ymean = ymax - yscale / 2;
double zmean = zmax - zscale / 2;

gl.glRotatef( 20, 0.0f, 1.0f, 0.0f );

for (int i = 0; i < indices.length; i = i + 3) {
double x1 = vertices[indices[i] * 3];
double y1 = vertices[indices[i] * 3 + 1];
double z1 = vertices[indices[i] * 3 + 2];
double x2 = vertices[indices[i + 1] * 3];
double y2 = vertices[indices[i + 1] * 3 + 1];
double z2 = vertices[indices[i + 1] * 3 + 2];
double x3 = vertices[indices[i + 2] * 3];
double y3 = vertices[indices[i + 2] * 3 + 1];
double z3 = vertices[indices[i + 2] * 3 + 2];

x1 -= xmean;
y1 -= ymean;
z1 -= zmean;

x2 -= xmean;
y2 -= ymean;
z2 -= zmean;

x3 -= xmean;
y3 -= ymean;
z3 -= zmean;

x1 = (x1 / xscale) * 1.5;
y1 = (y1 / yscale) * 1.5;
z1 = (z1 / zscale) * 1.5;

x2 = (x2 / xscale) * 1.5;
y2 = (y2 / yscale) * 1.5;
z2 = (z2 / zscale) * 1.5;

x3 = (x3 / xscale) * 1.5;
y3 = (y3 / yscale) * 1.5;
z3 = (z3 / zscale) * 1.5;

gl.glBegin(GL2.GL_LINES);
gl.glVertex3d(x1, y1, z1);
gl.glVertex3d(x2, y2, z2);
gl.glVertex3d(x3, y3, z3);
gl.glVertex3d(x1, y1, z1);
gl.glEnd();
System.out.println("i: "+x1+" "+y1+" "+z1+ " - "+x2+" "+y2+" "+z2+" - "+x3+" "+y3+" "+z3);
try {
GLU glu = new GLU();
GLProfile gl_profile = GLProfile.get(GLProfile.GL2ES2); // GLProfile.getDefault();
GLCapabilities capabilities = new GLCapabilities(gl_profile);
capabilities.setOnscreen(false);
GLDrawableFactory factory = GLDrawableFactory.getFactory(gl_profile);
GLOffscreenAutoDrawable drawable = factory.createOffscreenAutoDrawable(null, capabilities, null, width, height);
drawable.addGLEventListener(new OffscreenJOGL());
drawable.display();
drawable.getContext().makeCurrent();
GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
System.out.println("this.renderEngineModel.isPresent(): " + this.renderEngineModel.isPresent());
if (this.renderEngineModel.isPresent()) {

IfcOpenShellEntityInstance renderEngineInstance;
try {
renderEngineInstance = this.renderEngineModel.get().getInstanceFromExpressId(ifcProductExpressId.get().intValue());
if (renderEngineInstance != null) {
IfcGeomServerClientEntity geometry = renderEngineInstance.generateGeometry();
if (geometry != null && geometry.getIndices().length > 0) {

double xmax = Float.MIN_VALUE;
double ymax = Float.MIN_VALUE;
double zmax = Float.MIN_VALUE;
double xmin = Float.MAX_VALUE;
double ymin = Float.MAX_VALUE;
double zmin = Float.MAX_VALUE;

int[] indices = geometry.getIndices();
float[] vertices = geometry.getPositions();
for (int i = 0; i < indices.length; i = i + 3) {
double x1 = vertices[indices[i] * 3];
double y1 = vertices[indices[i] * 3 + 1];
double z1 = vertices[indices[i] * 3 + 2];
double x2 = vertices[indices[i + 1] * 3];
double y2 = vertices[indices[i + 1] * 3 + 1];
double z2 = vertices[indices[i + 1] * 3 + 2];
double x3 = vertices[indices[i + 2] * 3];
double y3 = vertices[indices[i + 2] * 3 + 1];
double z3 = vertices[indices[i + 2] * 3 + 2];

if (x1 < xmin)
xmin = x1;
if (x2 < xmin)
xmin = x2;
if (x3 < xmin)
xmin = x3;

if (x1 > xmax)
xmax = x1;
if (x2 > xmax)
xmax = x2;
if (x3 > xmax)
xmax = x3;

if (y1 < ymin)
ymin = y1;
if (y2 < ymin)
ymin = y2;
if (y3 < ymin)
ymin = y3;

if (y1 > ymax)
ymax = y1;
if (y2 > ymax)
ymax = y2;
if (y3 > ymax)
ymax = y3;

if (z1 < zmin)
zmin = z1;
if (z2 < zmin)
zmin = z2;
if (z3 < zmin)
zmin = z3;

if (z1 > zmax)
zmax = z1;
if (z2 > zmax)
zmax = z2;
if (z3 > zmax)
zmax = z3;
}
double xscale = xmax - xmin;
double yscale = ymax - ymin;
double zscale = zmax - zmin;

double xmean = xmax - xscale / 2;
double ymean = ymax - yscale / 2;
double zmean = zmax - zscale / 2;

gl.glRotatef(20, 0.0f, 1.0f, 0.0f);

for (int i = 0; i < indices.length; i = i + 3) {
double x1 = vertices[indices[i] * 3];
double y1 = vertices[indices[i] * 3 + 1];
double z1 = vertices[indices[i] * 3 + 2];
double x2 = vertices[indices[i + 1] * 3];
double y2 = vertices[indices[i + 1] * 3 + 1];
double z2 = vertices[indices[i + 1] * 3 + 2];
double x3 = vertices[indices[i + 2] * 3];
double y3 = vertices[indices[i + 2] * 3 + 1];
double z3 = vertices[indices[i + 2] * 3 + 2];

x1 -= xmean;
y1 -= ymean;
z1 -= zmean;

x2 -= xmean;
y2 -= ymean;
z2 -= zmean;

x3 -= xmean;
y3 -= ymean;
z3 -= zmean;

x1 = (x1 / xscale) * 1.5;
y1 = (y1 / yscale) * 1.5;
z1 = (z1 / zscale) * 1.5;

x2 = (x2 / xscale) * 1.5;
y2 = (y2 / yscale) * 1.5;
z2 = (z2 / zscale) * 1.5;

x3 = (x3 / xscale) * 1.5;
y3 = (y3 / yscale) * 1.5;
z3 = (z3 / zscale) * 1.5;

gl.glBegin(GL2.GL_LINES);
gl.glVertex3d(x1, y1, z1);
gl.glVertex3d(x2, y2, z2);
gl.glVertex3d(x3, y3, z3);
gl.glVertex3d(x1, y1, z1);
gl.glEnd();
System.out.println("i: " + x1 + " " + y1 + " " + z1 + " - " + x2 + " " + y2 + " " + z2 + " - " + x3 + " " + y3 + " " + z3);
}
}
}
} catch (RenderEngineException e) {
e.printStackTrace();
}
}
} catch (RenderEngineException e) {
e.printStackTrace();
}

gl.glFlush();
gl.glFlush();
}
BufferedImage im = new AWTGLReadBufferUtil(drawable.getGLProfile(), false).readPixelsToBufferedImage(drawable.getGL(), 0, 0, width, height, true);
return im;
} catch (Exception e) {
e.printStackTrace();
}
BufferedImage im = new AWTGLReadBufferUtil(drawable.getGLProfile(), false).readPixelsToBufferedImage(drawable.getGL(), 0, 0, width, height, true);
return im;

// If Jogl does not work:
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
paint(ig2);
return bi;

}

}
Loading

0 comments on commit 8fc000c

Please sign in to comment.