Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

how to select a vertex

Help
KC
2011-08-01
2013-04-22
  • KC
    KC
    2011-08-01

    Hi,

    I'm new to BRL-CAD.
    I need to work on STL and after convert STL to BRL-CAD's g file (via stl-g) I can
    successfully import my STL into mged.

    I need to edit/measure the STL via GUI or APIs.
    But I found BRL-CAD seems can only work on Shape level, not vertex level ?  Is this correct ?

    What I need to do on STL is simple, for example
    select two vertex, highlight them and measure the distance.
    something like that.

    Any suggestion is appreciated.  Thanks a lot.

    Regards,
    KC

     
  • Sean Morrison
    Sean Morrison
    2011-08-01

    In general, BRL-CAD is not well-suited to performing vertex operations, but there are actually hooks for selecting individual vertices on polygonal mesh geometry but it's very low-level.  That said, there's not a built-in simple way to calculate the distance of two arbitrary points.  You'd have to write a little Tcl script.  Very doable, but not automatic.

     
  • KC
    KC
    2011-08-01

    Hi,

    Thanks for your info.
    Could you give me some examples, or show me where should I looking at to
    access STL's vertex or triangle via Tcl script or C/C++ API ?
    As I said, I'm new to BRL-CAD … any information tell me where to start will be
    very useful for me.  Thanks a lot.

    Regards,
    KC

     
  • Sean Morrison
    Sean Morrison
    2011-08-02

    There's lots of ways to get at that vertex data from the Tcl and C API.  Before giving you "too much information", though, here's a simple Tcl snippet that will calculate the distance between two BoT  vertices:

    proc dist {args} {
      if { != 2} {
        puts "Usage: dist pt1 pt2"
        return
      }

      set obj [lindex  0]
      set p1 [ lindex   ]
      set p2 [ lindex   ]
      set d [ expr sqrt( pow( - , 2) + pow( - , 2) + pow( - , 2)) ]

      puts "Using vertices from $obj"
      puts "pt1: $p1"
      puts "pt2: $p2"
      puts "distance: $d"

      return $d
    }

    The "puts" printing at the end is entirely optional .  If you save that snippet to some file, say "dist.tcl" and then run "source dist.tcl" within mged, you'll be able to calculate the distance between two vertices just by knowing their vertex number.  Example use:

    opendb test.g y
    source dist.tcl
    make box.arb8 arb8
    facetize box.bot box.arb8
    B box.bot
    sed box.bot
    ae 35 25
    press "Pick Vertex"
    # click on two vertices, displays something like:
    # picked point at (499.953 -492.098 505.697), vertex #3
    # picked point at (492.053 507.871 505.142), vertex #1
    dist 3 1
    # displays distance between box.bot's points 3 and 1

    Cheers!
    Sean

    "BoT" is our triangle mesh entity type.  importing from STL creates a BoT mesh.
    Nearly the entire proc is optional since one could perform the vertex extraction and distance calculation with just one line.

     
  • KC
    KC
    2011-08-02

    Hi,

    Thanks a lot.  It works perfectly :-)  except one thing ….
    how can I capture vertex #1 and vertex #3 into Tcl's variable
    and make everything automatically ?  Is it possible ?

    Well, your reply is very helpful, thanks again.

    KC

     
  • KC
    KC
    2011-08-03

    how can I capture vertex #1 and vertex #3 into Tcl's variable and make everything automatically ? Is it possible ?

    OK, I simply search keyword "picked point at" in mged's source code and
    find it's not possible at this moment.   But modify the source to record the picked point
    in global Tcl variable looks not difficult, so I think I can start there for my project.

    I think bind a Tcl callback for GUI event is a good idea too (better than use a hard-coded global Tcl variable).

    Does the interactive between GUI and Tcl is in the roadmap of BRL-CAD ?
    Anyone think this is a good idea ?  Or BRL-CAD (mged) already has better approach for
    this kind of issue ?

    Regards
    KC

     
  • Sean Morrison
    Sean Morrison
    2012-05-14

    KC,

    Have you made any progress on your project?  If you have any modifications to mged or other source code that facilitate your project, I'll be glad to help you integrate them.  Binding a Tcl callback for GUI events is/was an outstanding idea.

    Cheers!
    Sean