Page 1 of 1

Get point id from coordinates

Posted: Wed Apr 22, 2020 3:47 pm
by JFlock_BE
Hello,

Is it possible to know if there is a point at a given coordinates x,y,z (taken into account a given tolerance) in tcl ?
If yes, is it possible to get its id ?

Thanks for your help !

Re: Get point id from coordinates

Posted: Thu Apr 23, 2020 9:02 pm
by escolano
No, it doesn't exists any GiD_Tcl command to get the closest or a list of points or other entities close to a center in a radius
Also we don't provide Tcl commands to wrap any 'finding structure' (like octree, kd-tree, bin, etc.) to do this kind of 3D space find efficiently

You must ask with Tcl entities data, and do this find by yourself, by brute-force (a loop over all entities) or using some more advanced data structure.

for small models or few finds the brute force solution could be enough

Note:
In the voro plugin once i have auxiliary used an vtkKdTree object (provided by the vtk Tcl package that we include in GiD to import/export vtk files)
to find points using this data structure.
Can see my code at <GiD>\plugins\Geometry\voro\voro.tcl
find inside the "vtkKdTree" word"

Re: Get point id from coordinates

Posted: Fri Apr 24, 2020 10:17 am
by JFlock_BE
Thanks for your answer, this is what I was thinking unfortunately.

I will check the voro plugin !

Thanks again !

Re: Get point id from coordinates

Posted: Fri Apr 24, 2020 10:40 am
by escolano
A bruce-force version is easy to write, e.g:

Code: Select all

proc GetClosestPointBruteForce { x y z tolerance } {
    set min_point_id -1
    set coordinate_find [list $x $y $z]    
    set mind_d2 1e30
    foreach poin_id [GiD_Geometry list point] {
        set point_xyz [lrange [GiD_Geometry get point $poin_id] 1 3]
        set d2 [MathUtils::VectorDistance2 $point_xyz $coordinate_find]
        if { $mind_d2>$d2 } {
            set mind_d2 $d2
            set min_point_id $poin_id
        }
    }
    if { $min_point_id != -1} {
        set mind_d [expr sqrt($mind_d2)]
        if { $mind_d > $tolerance } {
            set min_point_id -1
        }
    }
    return $min_point_id
}

Re: Get point id from coordinates

Posted: Fri Apr 24, 2020 2:13 pm
by JFlock_BE
Thanks for that, it could be usefull !

But most of the time, there are a lot of nodes (for instance, the model on which I currently work has more than 11 000 nodes... ) So I will try the solution with the vtkKdTree objects.

I was thinking also to use the GiD collapse function to know if there are points on a given coordinate (create new points wiht the given x,y,z and then collapsing all points and check if some points are deleted or not) but is it possible to get the id of deleted entities after collapsing ?


Thanks for your time.

Re: Get point id from coordinates

Posted: Fri Apr 24, 2020 7:36 pm
by escolano
11000 nodes is a relativelly small model
Note: my example code was made for geometry point, not for mesh nodes (must do some change to ask for mesh nodes)

Re: Get point id from coordinates

Posted: Mon Apr 27, 2020 7:11 am
by JFlock_BE
Yes 11k nodes is relatively small but I meant 11k points befor meshing, my fault sorry.

Many thanks for all your help.