Macro for selecting points for feature detection

Discuss PolyWorks here.
Post Reply
mlacht
I have made <0 posts
I have made <0 posts
Posts: 5
Joined: Thu Apr 11, 2019 1:57 pm
Full Name: Markus
Company Details: student
Company Position Title: student
Country: Germany
Skype Name: -
Linkedin Profile: No

Macro for selecting points for feature detection

Post by mlacht » Fri Apr 12, 2019 7:20 am

Hey there,

I want to write a macro to select points from a point cloud (.xyz file) to detect a feature e.g. Best fit of a plane.

I know how to write a script already to select all points of a point cloud:

Code: Select all

DECLARE count
DECLARE name
DECLARE i 1

# get number of all data elements
TREEVIEW DATA COUNT GET ( count )

# store all data names in name
TREEVIEW DATA NAME ALL GET ( name )

while $i <= $count
    TREEVIEW OBJECT VIEW RESTORE ( $name[$i] )
    
    SELECT ELEMENTS OPTIONS DATA_POINTS FROM_MESHES ( "Off" )
    SELECT ELEMENTS OPTIONS REFERENCE_TRIANGLES ( "Off" )
    SELECT ELEMENTS OPTIONS DATA_POINTS FROM_POINT_CLOUDS ( "On" )
    SELECT ELEMENTS MODE SELECTION_TYPE ( "Surface" )
    SELECT ELEMENTS ALL
    # Does not work:    
    #SELECT DATA_POINTS FROM_CURVATURE ( 10, 30, "Maximum Radius",  )
    
    # try: 
    #SELECT DATA_POINTS FROM_POINT_CLOUD_BOUNDARIES ( 10, 50 )
    
    FEATURE PRIMITIVE PLANE FIT_SELECTED_ELEMENTS ( "Measured", $name[$i], )    
    TREEVIEW OBJECT VIEW HIDE ( $name[$i])
    ++ i
ENDWHILE


However I only want to select particular points of a point cloud using a macro (By hand I use the "Mark" tool and simply mark them red and then fit my feature)

Does anyone know if there exists a nice list of example of macros for polyworks?

mlacht
I have made <0 posts
I have made <0 posts
Posts: 5
Joined: Thu Apr 11, 2019 1:57 pm
Full Name: Markus
Company Details: student
Company Position Title: student
Country: Germany
Skype Name: -
Linkedin Profile: No

Re: Macro for selecting points for feature detection

Post by mlacht » Wed Apr 24, 2019 7:18 am

I just found some official example macros at:

C:\Program Files\Duwe-3d\D3D++2018\RuntimeMacros


and one of them might solve the task:

SELECT DATA_POINTS FROM_REFERENCE_SURFACES.pwmacro

User avatar
frassolutions
I have made <0 posts
I have made <0 posts
Posts: 8
Joined: Thu Feb 14, 2019 2:36 pm
Full Name: Jean-Simon Fraser
Company Details: FRAS Solutions
Company Position Title: CEO
Country: Canada
Skype Name: jsfraser2
Linkedin Profile: Yes
Contact:

Re: Macro for selecting points for feature detection

Post by frassolutions » Thu May 02, 2019 9:12 pm

Polyworks doesn't have any function to automatically detect features based on geometry.

A work-around could be possible, but it would depend on the geometry of your data. If it is not too complex, there could be a way to do it. The idea would be to "know" in advance the features that you want to extract, and automate the selection by using various functions.

Your example suggest that you are working in IMedit, which is the reverse engineering module. I am more fond of IMinspect for this type of work. The selection tools are different.

Example (I hope that you have the normal information in your point cloud, since it really helps with filtering data):

Code: Select all

SELECT DATA_POINTS FROM_NORMAL_VECTORS ( "Closer than", 10.0, "+X" )
will select all the planes facing the +X direction. You can then fit a single plane fronm this selection, or fit the max plane:

Code: Select all

EDIT SPLIT REMOVE_SELECTION ( "YourDataName" )
SELECT ELEMENTS NONE
TREEVIEW OBJECT_ELEMENTS SELECT ALL ( "YourDataName (2)" )
FEATURE PRIMITIVE PLANE FIT TYPE ( "Max" )
FEATURE PRIMITIVE PLANE FIT_SELECTED_ELEMENTS ( "Measured", "plane 1", )
Now you have isolated all the data facing +X and fitted the furthest plane from that selection, because we use the "Max" type. You could create a loop and remove the data of that last plane, which will let you fit a new max plane the next time you run the fit function.

To do that, you can reselect the data close to that new plane like this:

Code: Select all

SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES OPTIONS PRIMITIVES SPECIFIC ( "plane 1 -meas-" )
SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES OPTIONS DATA_OBJECTS ( "Surface" )
SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES OPTIONS MAX_DISTANCE ( 2.0 )
SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES OPTIONS USE_MAX_ANGLE ( "On" )
SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES OPTIONS MAX_ANGLE ( 30.0 )
SELECT DATA_POINTS FROM_FEATURE_PRIMITIVES
With that new selection, you can create a best-fit plane, or unmark then deselect your previous selection. That way, you could iteratively select all the planes one by one and best-fit them.

Once you clear all the flat surfaces, you could then fit another feature type on the remaining data. Anytime you succeed at fitting a feature, you can hide the data of that feature to make it easier to select the next one.

This method works very well for simple geometries, when there is only a few features per file and when the geometries are very similar.
https://frassolutions.com
Automation of 3D measurements and portable 3D scanning services

jedfrechette
V.I.P Member
V.I.P Member
Posts: 863
Joined: Mon Jan 04, 2010 7:51 pm
Full Name: Jed Frechette
Company Details: Lidar Guys
Company Position Title: CEO and Lidar Supervisor
Country: USA
Linkedin Profile: Yes
Location: Albuquerque, NM
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Macro for selecting points for feature detection

Post by jedfrechette » Thu May 02, 2019 11:45 pm

frassolutions wrote:
Thu May 02, 2019 9:12 pm
This method works very well for simple geometries, when there is only a few features per file and when the geometries are very similar.
I'd emphasize this point. As you say, I could imagine doing something like this on a small point cloud, but I don't even want to think about how slow it would be for any reasonably sized data set.

I'm not sure they're exactly what the OP is after, but as another example of the types of things you can do with selections in PolyWorks I'll point to a couple macros that I wrote several years ago to extract geometric targets from point clouds. One was for extracting spheres and the other circles. In both cases the idea was that user would make a rough selection, which would then be refined based on a point intensity threshold.

https://sourceforge.net/p/tlspy/code/ci ... rget.macro
https://sourceforge.net/p/tlspy/code/ci ... rget.macro

I'm also more familiar with doing this sort of thing in IMInspect and those particular macros were actually written for IMSurvey, which doesn't exist anymore, but was basically a limited version of IMInspect. Note these were also written for an old version so some of the syntax probably needs to get updated. I wouldn't expect the changes to be to drastic though. In any case, I hope this helps and maybe gives you some ideas. If you dig around in that code repo you'll find a bunch of other macros for the various PolyWorks modules.

P.S. I'm glad to see at least one other person on this forum who's comfortable torturing PolyWorks. I've done some horrible horrible things with that macro language, but am happy to say that those horrible things have easily saved me thousands of hours.
Jed

User avatar
frassolutions
I have made <0 posts
I have made <0 posts
Posts: 8
Joined: Thu Feb 14, 2019 2:36 pm
Full Name: Jean-Simon Fraser
Company Details: FRAS Solutions
Company Position Title: CEO
Country: Canada
Skype Name: jsfraser2
Linkedin Profile: Yes
Contact:

Re: Macro for selecting points for feature detection

Post by frassolutions » Fri May 03, 2019 3:40 pm

Nice examples Jed.

Your macros are interactive and time saving, which can prove useful in many situations.

I don't consider my example a general solution. It is more of an eye opener, to see how some functions can be used. This type of automation requires us to be very creative.

From experience, most of the time, I have to code a new macro for a new project. It is very situational, but as you said, it can save us thousands of hours. Very often, I have a huge project that would take me a week or two of tedious work. By automating parts of it, I can reduce the data extraction time by 5X or more. 4 to 6 hours to build the macro, plus 1 -2 hours to finish the job manually, instead of 40h or more of repetitive tasks.

I sometimes develop macros for my customers, and most of the time they don't want the macro to be interactive: they want that magic button that does everything and they just need to wait until it is done. If you shut down all the windows refresh options in Polyworks, it is possible to extract hundreds of features within a few seconds. It takes more time to develop the macro, but it pays off if there are many features to extract.

I once had to inspect a bunch of structural steel I beams forming 30 arches aligned along the same path. I created an automation based on calipers and features. The calipers detect the location of the first arch, then a set of features is extracted. The features are built based on the relative estimated distance between each other. Once this is done, the macro looks for the next arch (estimated distance between the arches) and run the calipers again to prepare for the next set of features. At the end, the macro was a one-button script that extracted about 600 features.

The beauty of this is that even if the arches are not perfectly aligned and are not of the same height, you can use the results from the last arch and provide a large enough range with the calipers to perfectly guess the location and size of the next arch without any manual interaction.
I'm also more familiar with doing this sort of thing in IMInspect and those particular macros were actually written for IMSurvey, which doesn't exist anymore, but was basically a limited version of IMInspect.
IMsurvey was almost the same software, they change x-y-z coordinates for North-East-Height just for convenience and removed some functions to make it look "easier".
P.S. I'm glad to see at least one other person on this forum who's comfortable torturing PolyWorks. I've done some horrible horrible things with that macro language, but am happy to say that those horrible things have easily saved me thousands of hours.
Haha, you have no idea how far I went torturing Polyworks. At some point, it looks more like software development than scripting.
https://frassolutions.com
Automation of 3D measurements and portable 3D scanning services

jedfrechette
V.I.P Member
V.I.P Member
Posts: 863
Joined: Mon Jan 04, 2010 7:51 pm
Full Name: Jed Frechette
Company Details: Lidar Guys
Company Position Title: CEO and Lidar Supervisor
Country: USA
Linkedin Profile: Yes
Location: Albuquerque, NM
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Macro for selecting points for feature detection

Post by jedfrechette » Fri May 03, 2019 5:05 pm

frassolutions wrote:
Fri May 03, 2019 3:40 pm
The features are built based on the relative estimated distance between each other. Once this is done, the macro looks for the next arch (estimated distance between the arches) and run the calipers again to prepare for the next set of features. At the end, the macro was a one-button script that extracted about 600 features.
That's pretty clever.

The interesting thing about using the PolyWorks Macro language is that as a programming language it is extremely primitive, but because you have direct access to all of the PolyWorks tools you can do an awful lot as long as you are a little creative about how to approach the problem. If they were using a general purpose language like Python instead the combination would be amazing.

Have you ever developed any plugins using the PolyWorks C++ SDK?
Jed

User avatar
frassolutions
I have made <0 posts
I have made <0 posts
Posts: 8
Joined: Thu Feb 14, 2019 2:36 pm
Full Name: Jean-Simon Fraser
Company Details: FRAS Solutions
Company Position Title: CEO
Country: Canada
Skype Name: jsfraser2
Linkedin Profile: Yes
Contact:

Re: Macro for selecting points for feature detection

Post by frassolutions » Fri May 03, 2019 6:23 pm

Have you ever developed any plugins using the PolyWorks C++ SDK?
I have used the SDK, but not in C++. I already have almost a dozen projects done with the SDK.

I have a Python module to handle the Polyworks COM objects. That's the language I prefer, because I can use mathematical modules like Numpy and Scipy. Together with Polyworks, that's 3D automation on steroids.
https://frassolutions.com
Automation of 3D measurements and portable 3D scanning services

jedfrechette
V.I.P Member
V.I.P Member
Posts: 863
Joined: Mon Jan 04, 2010 7:51 pm
Full Name: Jed Frechette
Company Details: Lidar Guys
Company Position Title: CEO and Lidar Supervisor
Country: USA
Linkedin Profile: Yes
Location: Albuquerque, NM
Has thanked: 2 times
Been thanked: 8 times
Contact:

Re: Macro for selecting points for feature detection

Post by jedfrechette » Fri May 03, 2019 6:33 pm

frassolutions wrote:
Fri May 03, 2019 6:23 pm
I have a Python module to handle the Polyworks COM objects. That's the language I prefer, because I can use mathematical modules like Numpy and Scipy. Together with Polyworks, that's 3D automation on steroids.
Very nice!
Jed

Post Reply

Return to “PolyWorks”