1 Reply Latest reply: Aug 4, 2014 10:12 AM by Ricardo AV RSS

    Isometric camera view image generation problem.

    2658946

      Problem :

      When i am trying to generate isometric(camera view)image of CAD file of size 24 MB, I am able to getting good resolution image.

      But same thing when i am trying to generate isometric image of CAD file of size 69 MB, I am not able to generate proper image, image size is too small and it is hardly visible while viewing in image viewer


      Work Around:

      We did a work around to resolve the problem . Work around code is given below.I request     "AutoVue Development team" to provide feedback on the code.


      package com.mimd.tms;

      import java.awt.Color;

      import java.awt.image.BufferedImage;

      import java.io.File;

      import java.io.FileOutputStream;

      import java.io.IOException;

      import java.util.ArrayList;

      import java.util.HashMap;

      import java.util.List;

      import java.util.Map;

      import java.util.regex.Matcher;

      import java.util.regex.Pattern;

      import javax.annotation.Resource;

      import javax.imageio.ImageIO;

      import javax.swing.JFrame;

      import com.cimmetry.common.SMColorsConfiguration;

      import com.cimmetry.core.ConvertOptions2D;

      import com.cimmetry.core.DocID;

      import com.cimmetry.core.HMatrix;

      import com.cimmetry.core.NodeModifier;

      import com.cimmetry.core.PAN_CtlPoint;

      import com.cimmetry.core.PAN_CtlRange;

      import com.cimmetry.core.RasterConvertOptions;

      import com.cimmetry.core.TreeModifier;

      import com.cimmetry.core.ViewState3D;

      import com.cimmetry.jvue.JVue;

      import com.cimmetry.jvue3d.Vue3DUtil;

      import com.cimmetry.jvue3d.VueCamera;

      import com.cimmetry.jvue3d.VueEntity;

      import com.cimmetry.util.Util;

      import com.cimmetry.vuebean.Vue3DController;

      import com.cimmetry.vuebean.VueBean;

      import com.cimmetry.vuebean.event.VueEvent;

      import com.cimmetry.vuebean.event.VueEventBroadcaster;

      import com.cimmetry.vuebean.event.VueFileListener;

      import com.cimmetry.vueconnection.ServerControl;

      import com.sun.opengl.util.FileUtil;

       

       

      public class AutovueImageGeneratorImpl implements VueFileListener{

        private String outputFolder = "C:\\Docs\\CadImages";

        private String autovueHostAdress = "socket://172.31.28.62:5099";

        private String inputFilePath = "C:\\Users\\Administrator\\Desktop\\141";

       

       

       

       

       

        com.cimmetry.jvue.JVue jvue = new com.cimmetry.jvue.JVue();

        protected ServerControl control = null;

       

       

        protected VueBean bean = null;

       

       

        public static List<String[]> views = new ArrayList<>();

       

       

        String[] views250 = { "ISOMETRIC", "TOP", "BOTTOM", "FRONT", "BACK",

        "LEFT", "RIGHT" };

       

       

        String[] views125 = { "ICON" };

       

       

        protected int[] imageSizes = { 250 };

       

        // Standard Views

        public static final int ISOMETRIC = 0;

        public static final int TOP = 1;

        public static final int BOTTOM = 2;

        public static final int FRONT = 3;

        public static final int BACK = 4;

        public static final int LEFT = 5;

        public static final int RIGHT = 6;

        protected String imgType = null;

        public static final int ICON = 7;

       

        static{

       

        }

       

        public static void main(String args[]){

        AutovueImageGeneratorImpl autovueImageGeneratorImpl = new AutovueImageGeneratorImpl();

        autovueImageGeneratorImpl.extractImagesFromCadFile();

       

       

        }

       

       

       

       

        public void extractImagesFromCadFile() {

       

       

        /*

        * Connecting to autovue server using http.

        */

        setAutovueEvironment(autovueHostAdress, "USER");

        setVueBeanObj();

        //convertToBmp();

       

       

       

        }

       

       

        private void setAutovueEvironment(String autoVueHostAddress, String user) {

        control = new ServerControl();

        try {

        control.setHost(autoVueHostAddress);

        control.connect();

        control.setUser(user);

        control.sessionOpen();

        } catch (Exception e) {

        e.printStackTrace();

       

        }

       

       

        }

       

       

        private void setVueBeanObj() {

        String m_format = "AUTO";

        JFrame m_frame = null;

        m_frame = new JFrame("CSI AWT Sample");

        m_frame.setBounds(80, 80, 540, 380);

       

       

        bean = new VueBean(m_format);

        bean.setServerControl(control);

        bean.setVueEventBroadcaster(bean.getVueEventBroadcaster());

        m_frame.getContentPane().add(bean);

        m_frame.setVisible(false);

        // Add the vuebean to the frame

        m_frame.add(bean);

        m_frame.setVisible(false);

        /*

        * Writing file to temp location

        */

       

       

       

       

        AddFileListener();

        bean.setFile("upload://"+inputFilePath);

       

       

        // Set all views

       

       

       

        }

        public void AddFileListener() {

              

               VueEventBroadcaster veb = bean.getVueEventBroadcaster();

               veb.addFileListener(this);

              

         }

        public void onFileEvent(VueEvent e)

        {

          if(e.getEvent() == VueEvent.ONPAGELOADED)

          {

          views.add(0, views250);

              convertToBmp();

              String bmpDir = outputFolder;

       

          }

        }

       

       

        private void convertToBmp(

        ) {

       

       

       

       

       

        String fileView = "";

       

       

       

       

       

        for (int imageSizeCount = 0; imageSizeCount < imageSizes.length; imageSizeCount++) {

       

       

        if (!bean.is3dPage()) {

        System.out.println("NOT #D");

        }

       

       

        String[] viewList = views.get(imageSizeCount);

        Integer viewListLength =viewList.length + 1;

        Integer count = 0;

        for (int viewListCount = 0; viewListCount < viewListLength; viewListCount++,count++) {

        if (viewListCount == 7) {

        count = 0;

        }

        setStandardView(count); // set standard view j

        // Create BMP

        switch (count) {

        case FRONT:

        fileView = "front";

        break;

        case BACK:

        fileView = "back";

        break;

        case RIGHT:

        fileView = "right";

        break;

        case LEFT:

        fileView = "left";

        break;

        case TOP:

        fileView = "top";

        break;

        case BOTTOM:

        fileView = "bottom";

        break;

        case ISOMETRIC:

        fileView = "isometric";

        break;

        case ICON:

        fileView = "icon";

        break;

        default:

        break;

        }

       

       

        String bmpDir = outputFolder ;

       

       

        File f = new File(bmpDir);

       

       

        if (!f.exists()) {

        f.mkdirs();

        }

       

       

        String fileNamePattern = bmpDir + File.separator + fileView

        + ".bmp";

       

       

        ConvertOptions2D opts = new RasterConvertOptions();

        double dim = imageSizes[imageSizeCount];

        opts.setFormat("PCRS_BMP");

       

        opts.setFileName(fileNamePattern);

        opts.setWidth(dim);

        opts.setHeight(dim);

        PAN_CtlRange ps = bean.getPageSizeEx();

        HMatrix hm = bean.getController().get3DController().getCamera()

        .getModelViewTransform(null);

        Vue3DUtil.transform(hm, ps, null, ps);

        opts.setInputRange(ps);

        ConvertOptions2D opts2D = opts;

        opts2D.setInputRange(getViewExtents(opts2D));

        opts2D.setArea(ConvertOptions2D.AREA_DISPLAY);

        opts2D.setTreeModifier(get3DState(opts2D));

        System.out.println("Camera View ::"+fileView);

        System.out.println("Camera Position ::"+opts2D.getTreeModifier().getCameraPosition());

        Color fgColor = SMColorsConfiguration.getColor(

        bean.getProfile(), SMColorsConfiguration.ENTITYDEF);

        if (bean.is3dPage() && fgColor != null) {

        opts2D.setForeground(Util.jToWinRGB(fgColor));

        }

       

       

        bean.convert(opts2D);

       

       

        /**

        * Adding file infomration to t_file_store table

        *

        */

       

       

       

       

       

        }

        }

       

       

        }

       

       

        /**

        * Sets each of the Standard Views

        *

        * @param type

        *            The View to Set

        */

        private void setStandardView(int type) {

       

       

        // Target point that the camera is looking at

        // Note: Points initialized to (0,0,0)

        PAN_CtlPoint target = new PAN_CtlPoint();

        // Point where the camera is located

        PAN_CtlPoint camera = new PAN_CtlPoint();

        // Up direction (vector) of the camera

        PAN_CtlPoint upDir = new PAN_CtlPoint();

        // radius (distance between the camera and the target)

        double r = 0.0;

        try {

        r = bean.getController().get3DController().getModelExtents()

        .getRadius() * 3;

        } catch (Exception e) {

        e.printStackTrace();

        }

       

       

        // Set the view to each of the Standard Views

        switch (type) {

        case FRONT:

        // move the camera away from target by 'r'

        camera.x = r;

        // Up direction of the camera is in the positive Z direction

        upDir.z = 1.d;

        break;

        case BACK:

        camera.x = -r;

        upDir.z = 1.d;

        break;

        case RIGHT:

        camera.y = r;

        upDir.z = 1.d;

        break;

        case LEFT:

        camera.y = -r;

        upDir.z = 1.d;

        break;

        case TOP:

        camera.z = r;

        upDir.x = -1.d;

        break;

        case BOTTOM:

        camera.z = -r;

        upDir.x = 1.d;

        break;

        case ISOMETRIC:

        System.out.println("R::R"+r);

        camera.setPoint(r, r, r);

        camera.scale(Math.sqrt(1.d / 1000));

        camera.normalize();

        upDir.z = 1.d;

        break;

        }

       

       

       

       

        ViewState3D viewState = new ViewState3D(null);

        // Set Camera to the new values

        viewState.setCameraPosition(camera);

        viewState.setCameraTargetPosition(target);

        viewState.setCameraUpDirection(upDir);

        viewState.setViewExtents(bean.getController().get3DController()

        .getModelExtents());

       

       

       

        // Set the viewstate to the Camera's viewstate and zoom fit

        bean.getController().get3DController().setViewState(viewState);

        bean.getController().get3DController().zoomFit();

       

       

        }

       

       

        /**

        * Gets the View Extents for the file to be converted View Extents are based

        * on the bounding box of the opened model as well as the camera settings of

        * the current view

        *

        * @param options

        *            ConvertOptions2D to be used for the conversion

        */

        private PAN_CtlRange getViewExtents(ConvertOptions2D options) {

       

       

        // Printout view extents

        PAN_CtlRange ve;

        Vue3DController ctl3d = bean.getController().get3DController();

       

       

        // Create a Matrix for the entire VueEntity Transform

        ve = new PAN_CtlRange();

        HMatrix hm = ctl3d.getVueEntity().getEntityTransform()

        .getCompleteTransform(null);

        ve = ctl3d.getVueEntity().getEntityInfo().getBoundingBox(ve)

        .getMaxExtents(ve);

        ve = Vue3DUtil.transform(hm, ve, null, ve);

       

       

        // Apply the Camera's Transform to our Matrix

        hm = ctl3d.getCamera().getViewTransform(hm);

       

       

        // Apply our Matrix to the VueEntity

        ve.moveTo(hm.getTranslation(null));

       

       

       

       

        return ve;

        }

       

       

        /**

        * Gets the TreeModifer for the file to be converted The Tree modifier has

        * information on the camera settings being used for the conversion

        *

        * @param options

        *            ConvertOptions2D to be used for the conversion

        */

        private TreeModifier get3DState(ConvertOptions2D options) {

       

       

        Vue3DController ctl3d = bean.getController().get3DController();

        PAN_CtlPoint pt = new PAN_CtlPoint();

        TreeModifier tm = new TreeModifier();

       

       

        // Get the Camera's Transform Matrix

        VueCamera camera = ctl3d.getCamera();

        HMatrix modelTransform = camera.getModelTransform(null);

       

       

        // Set model transform

        tm.setModelTransform(modelTransform);

       

       

        // Set view transform

        tm.setCameraPosition(camera.getCameraPosition(pt));

        tm.setCameraTargetPosition(camera.getCameraTargetPosition(pt));

        tm.setCameraUpDirection(camera.getCameraUpDirection(pt));

       

       

       

        // Get nodes modifiers

        NodeModifier[] mods = ctl3d.getModifiers();

       

       

        // Set nodes modifiers

        tm.setNodeModifiers(mods);

       

       

        // Return TreeModifier

       

       

        return tm;

        }

       

       

        public void imageConversion(String imageDirectory) {

        String imagePath = imageDirectory;

        String jpgFileName;

       

       

        // Get list of files from standard image directory

        String[] imageList = listOfFiles(imageDirectory);

        Pattern p = Pattern.compile("^(.+).bmp?");

        Matcher m;

        for (int i = 0; i < imageList.length; i++) {

       

       

        m = p.matcher(imageList[i]);

        if (m.matches()) {

        jpgFileName = imageList[i].substring(0,

        imageList[i].indexOf(".bmp"))

        + ".jpg";

       

       

        File f = new File(imageDirectory + File.separator

        + imageList[i]);

        try {

        BufferedImage bufi = ImageIO.read(f);

        File file = new File(imagePath + File.separator

        + jpgFileName);

        ImageIO.write(bufi, "jpg", file);

        f.delete();

        } catch (Exception e) {

        e.printStackTrace();

        }

        } else {

        }

        }

        }

       

       

        String[] listOfFiles(String imageDirectory) {

       

       

        File file = new File(imageDirectory);

        String[] imageList = file.list();

        return imageList;

        }

       

       

      }

       

       

       


        • 1. Re: Isometric camera view image generation problem.
          Ricardo AV

          Hello,

          I appreciate you sharing the code with the community

          But I would like to point out that

          Isometric view already exist and is working fine

          conversion to BMP also exists and is also working fine

          Combining both, is also a simple task

           

          Not sure why you state your code is a work around, so why don't you start by describing the issue you are facing better so that we can help you

          Perhaps, you missed a very simple step in your code, as setting a large enough image size when you invoked convert?

          Is the isometric camera distance too far away (it is a view after all, camera distance is not specified) ?