Showing posts with label 3D. Show all posts
Showing posts with label 3D. Show all posts

Monday, July 11, 2022

Blender: how to make an edge flush with another edge by snapping and scaling

Making an plane edge geometry flush with another plane geometry is a typical CAD task. In Blender 3D, it is possible to do the same using simple Move and Scale commands, but with the right settings. 

The screenshot below shows 2 plane objects in the top view. This post shows the steps to adjust the bottom plane to snap nicely to the plane on the left.

Set to Snap to Vertex

  1.  In the Blender 3D Viewport menu bar, click the Snap icon and choose Vertex as shown below.




Snap the vertex of one plane to the vertex of the other plane

  1. In the Blender 3D Viewport, make sure the Edit Mode is enabled and Select Mode is Vertex.

  2. In the Blender Toolbar, select the Move icon. Then click on the bottom vertex of the plane to be moved.

  3. On the keyboard, press down CTRL and drag the bottom vertex to snap to the vertex of the other plane.


     

 Scale the edge vertices by axis to zero

  1. In the Blender 3D Viewport menu, set the Transform Pivot Point to Active Element as shown below.




     
  2. On the keyboard, press ALT-a to deselect all selection.

  3. In the Toolbar, click the Select Box icon.




  4. Click the top vertex of the plane to be scaled.

  5. Press SHIFT and click the bottom vertex.

    Note: since the Transform Pivot Point is set to Active Element, the scaling will be relative to the last selected vertex.

  6. Press S.

    The plane scales dynamically around the last selected vertex as the cursor is moved.


  7. Limit the direction of scaling to the X-axis (in this example) which is perpendicular to the matching edges. Press X.

    The plane can only scale along the X axis.


  8. Press 0.

    The planes are snapped nicely to one another.

Monday, May 4, 2020

Gazebo: make an animated box using a separate model file(s)

The Gazebo tutorial at http://gazebosim.org/tutorials?tut=actor&cat=build_robot shows how to make a box actor rotate around the vertical axis using only a world file. I wanted to use create a separate actor model and include it in the world file so I don't have to repeat the code. After fiddling around, I managed to figure out the procedure to do it. This post summarizes the steps.

Create an actor model
  1. In the user's home directory ~/.gazebo/models/, create a model folder, e.g. animated_box

    $ cd ~/.gazebo/models/
    $ mkdir -p animated_box/materials/scripts
    $ mkdir -p animated_box/materials/textures


  2. Change directory into the animated_box folder.

    $ cd animated_box


  3. Using a text editor, create a model.config file. Type in the following:
    <?xml version="1.0" encoding="utf-8"?>
    <model>
     <name>Animated Box</name>
     <version>1.0</version>
     <sdf version="1.4">model.sdf</sdf>
     <description>My animated box</description>
    </model>
    


  4. Using a text editor, create a model.sdf file. Type in the following:

    Note: instead of the model tag, use the actor tag.
    <?xml version="1.0" encoding="utf-8"?>
    <sdf version="1.4">
     <actor name="animated_box">
      <static>false</static>
       <link name="link">
        <visual name="visual">
         <geometry>
          <box>
           <size>0.2 0.2 0.2</size>
          </box>
         </geometry>
        </visual>
       </link>
       <script>
        <loop>true</loop>
        <delay_start>0.0</delay_start>
        <auto_start>true</auto_start>
        <trajectory id="0" type="square">
         <waypoint>
          <time>0.0</time>
          <pose>-1 -1 1 0 0 0</pose>
         </waypoint>
         <waypoint>
          <time>1.0</time>
          <pose>-1 1 1 0 0 0</pose>
         </waypoint>
         <waypoint>
          <time>2.0</time>
          <pose>1 1 1 0 0 0</pose>
         </waypoint>
         <waypoint>
          <time>3.0</time>
          <pose>1 -1 1 0 0 0</pose>
         </waypoint>
         <waypoint>
          <time>4.0</time>
          <pose>-1 -1 1 0 0 0</pose>
         </waypoint>
        </trajectory>
       </script>
    
     </actor>
    </sdf>
    


Create and run the world file
  1.  Using a text editor, create a world file, e.g. my_animated_box.world. Type in the following commands:
    <?xml version="1.0" ?>
    <sdf version="1.3">
     <world name="default">
      <include>
      <uri>model://sun</uri>
      </include>
      <include>
       <uri>model://ground_plane</uri>
      </include>
      <include>
       <uri>model://animated_box</uri>
      </include>
     </world>
    </sdf>
    

    Note: the previously created animated_box model is included as a model.

  2. Run the world file.

    $ gazebo my_animated_box.world

    Gazebo opens and an animated box is shown circling the z axis.

    Monday, March 9, 2020

    Using Saga GIS' Terrain Analysis Swath Profile (interactive) function

    Saga GIS has a couple of interactive terrain profiling functions, a single profile and a swath profile. This post shows how to use the interactive swath terrain profile command.

    Load a grid file such as a USGS SRTM file
    1. Run Saga GIS. Select Geoprocessing | File | Grid | Import | Import USGS SRTM Grid.

      The Import USGS SRTM Grid dialog box appears.
    2. Click the Browse button in the Files field. Choose an SRTM file e.g. N21E093.hgt.

    3. Click Open.

    4. Click Okay.

      The SRTM file is loaded and shown in the Data tab.
    Start the swath profile command
    1.  Under the Data tab, mouse right click on the loaded grid file e.g. N21E093.
    2. In the pop up context menu, choose Add to Map.

      The grid file is displayed in a map window.
    3. Select Geoprocessing | Terrain Analysis | Profiles | Swath Profle [Interactive].

      The Swath Profile dialog box appears.
    4. In the Grid system field, choose the loaded grid file's system e.g. 0.000833; 1201x 1201y; 93x 21y option.
    5. In the DEM field, choose the loaded grid file, e.g. N21E093.
    6. Optional. Change the Swath Width if necessary.

      The message Interactive tool execution has been started is displayed in the Messages pane.
    Digitize the swath profile
    1. In the Toolbar, click the Action icon (that looks like a black NW arrow).
    2. In the map window, click a few points to draw the swath profile.


    3. To complete the drawing, press the mouse right button.
    4. To exit the interactive command, select Geoprocessing | Swath Profle [Interactive].

      The Tool Execution prompt appears.
    5. Click Yes.

      The message: "Interactive tool execution has been stopped" is shown in the Messages pane.

      Note: This may take a while as the command will sample the terrain to calculate the points.
    Display the swath profile graphically
    1.  In the Data pane, mouse right click on the newly created profile points e.g. Profile [N21E093].

    2. In the pop up menu, choose Attributes | Diagram.

      The Properties dialog box appear.
    3. In the X Axis Values field, choose D (for Distance).
    4. In the X Axis Label field, choose D.
    5. In the Attributes field, toggle on Z, Z [min], Z[max].
    6. Set other options if necessary.
    7. Click Okay.

      The profile line(s) are displayed.

    Monday, April 29, 2019

    Create a Facebook 3D Photo of a digital elevation model using QGIS

    Facebook has a 3D photo feature which brings perspective and movement to the Facebook news feed and timeline images. A live example can be seen embedded here:


    Normally these images are created using RGB-D cameras, where D stands for depth. However it is also possible to workaround it without a RGB-D camera by uploading to Facebook two images - an RGB image and its corresponding grayscale depth image, and making sure the depth image has the same name as the RGB image with a '_depth' suffix. The depth image is grayscale only with values ranging from dark to light -  the dark pixels representing the furthest pixels and the light pixels representing the nearest pixels.

    Using the ideas above, the following steps illustrate how to create a Facebook 3D Photo image from a SRTM digital elevation model (DEM) using QGIS.

    1. Startup QGIS. Create a new project. If the canvas background is not already black, select Project | Project Properties.

      The Project Properties dialog box appears.
    2. In the Background color field, change the color to black. Click OK.

      The canvas background becomes black.
    3. Drag and drop a DEM file onto the canvas e.g. srtm_54_07.tif.

       
    4.  Optional. To serve the purpose of having a background, an OpenStreetMap (OSM) layer is displayed behind the DEM layer.

    5. Optional. To display only DEM heights above an elevation of interest, e.g. 200 meters, right click on the DEM layer and choose Properties. Then add in a new transparent entry to the transparent pixel list from 0 to 200 meters, as shown below. Then click OK.

      The Layer Properties dialog box appears.



      The DEM display is updated.

    6. Make a duplicate of the DEM layer by right clicking on the DEM layer and choosing Duplicate. Rename the copy as 'depth' as it will serve to generate a depth image later on.

    7. Right click on the top most DEM layer and choose Properties. In the Layer properties dialog box, click Style.

    8. Change the Render Type to Hillshade. Click OK.

      The DEM layer is now rendered as a hill shade.
    9. Make a duplicate copy of the hill shaded DEM layer by right clicking the layer and choosing Duplicate. Rename the copy as 'hillshade' as shown below.

    10. Right click on the top most DEM layer and choose Properties. Select the Style tab.

    11. In the Rendering type field, choose Singleband pseudocolor. Choose a suitable color gradient e.g. Spectral and toggle Invert if necessary. Choose a suitable Blending mode e.g. Screen.

    12. Click OK.

      The DEM layer is rendered with a colored gradient.
    13. With the gradient colored, hill shaded and OSM layers displayed on and the depth layer displayed off, export out the canvas by selecting Project | Save as image and specifying an output file name e.g. srtm.png.

      The srtm image is generated.
    14. Now turn off the gradient, hill shaded and OSM layers. Turn on the depth layer as shown below.




      Select Project | Save as image to export out the depth image with a '_depth' suffix e.g. srtm_depth.png.

      The srtm_depth image is generated.
    15. Now open up Facebook in a browser and click the Post Photo/Video button.

      The File Upload dialog box appears.
    16. Browse and select the generated srtm.png and srtm_depth.png files. Click Open.

      Facebook generates the 3D Photo.


      A live example is available here at https://www.facebook.com/permalink.php?story_fbid=1251984134967474&id=101193703379862

    Monday, May 21, 2018

    Perform a 2D geo-registration of a LiDAR LAS file to a GeoTiff image with Cloud Compare

    Recently I received LiDAR LAS point clouds generated without using accurate GPS positioning. As a result, the data is not placed at the correct geographic location in the world. To rectify this, I used Cloud Compare to so-called geo-register the point clouds to the world using GeoTiff images as reference.

    The following illustrates how it was done:

    Load the GeoTiff image as reference
    1. Start Cloud Compare.


    2. Select File | Open.

      The Open file(s) dialog box appears.

    3. Browse and select the reference GeoTiff raster file, e.g. autzen.tif. Click Open.

      The Result type prompt appears.

    4. Click No to load as a texture map instead of converting to a point cloud.

      The Global shift/scale dialog box appears.

    5. Accept the defaults. Click Yes.

      The GeoTiff image is loaded.
    Load the LAS file
    1. Select File | Open.


    2. Browse and choose the LAS file, e.g. autzen.las. Click Open.

      The Open LAS File dialog box appears.
    3. Click Apply.

      The Global shift/scale dialog box appears.

    4. Click Yes to accept the defaults.

      The LAS file is loaded.
     Setup the display
    1. In the vertical tool bar on the left, click the Set Current View Mode icon
      and choose Orthographic projection.

      Note: we do not want the perspective projection display to mislead us as to the location of the features
    2. Optional. Select Edit | Colors | Height Ramp. Click OK in the Gradient color dialog box to display the point cloud with a height color gradient for better visualization.


    Perform the rectification
    1.  In the DB Tree pane, select the point cloud to rectify, e.g. autzen.las.
    2. In the top tool bar, click the Translate/Rotate icon .

      The Translate/Rotate widget appears in the top right corner.
    3. In the Rotation field, select Z. Toggle off Tz.

      Note: we only want to move horizontally in the 2D plane.
    4. Look for matching features in the point cloud and the GeoTiff image.



    5. To translate the point cloud, press down the mouse right button and drag the point cloud to the new location. To rotate the point cloud, press down the mouse left button and rotate the point cloud.

      Note 1: To toggle the display of the point cloud, toggle on/off the Visible property in the Properties pane on the left.
      Note 2: To zoom in/out/pane around, pause the Translate/Rotate widget by clicking the widget's Pause icon.
    6. In the Translate/Rotate widget, click the Tick icon to save the changes.

      The point cloud is rectified.