Results 1 to 7 of 7

Thread: Slow creating 3DFaces

  1. #1
    Yves Guest

    Slow creating 3DFaces

    Hi, I have a very simple code that reads an ASCII file to extract Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.

    For i = 1 To CntTri - 1
    FacePt1(0) = VtxX.Item(Tri1.Item(i))
    FacePt1(1) = VtxY.Item(Tri1.Item(i))
    FacePt1(2) = VtxZ.Item(Tri1.Item(i))
    FacePt2(0) = VtxX.Item(tri2.Item(i))
    FacePt2(1) = VtxY.Item(tri2.Item(i))
    FacePt2(2) = VtxZ.Item(tri2.Item(i))
    FacePt3(0) = VtxX.Item(Tri3.Item(i))
    FacePt3(1) = VtxY.Item(Tri3.Item(i))
    FacePt3(2) = VtxZ.Item(Tri3.Item(i))
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next

  2. #2
    James Belshan Guest
    The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
       For i = 1 To CntTri - 1
           t1 = Tri1.Item(i)
           t2 = Tri2.Item(i)
           t3 = Tri3.Item(i)
          FacePt1(0) = VtxX.Item(t1)
          FacePt1(1) = VtxY.Item(t1)
          FacePt1(2) = VtxZ.Item(t1)
          FacePt2(0) = VtxX.Item(t2)
          FacePt2(1) = VtxY.Item(t2)
          FacePt2(2) = VtxZ.Item(t2)
          FacePt3(0) = VtxX.Item(t3)
          FacePt3(1) = VtxY.Item(t3)
          FacePt3(2) = VtxZ.Item(t3)
          Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
       Next
    If you can make collections of user-defined-types (I don't know about this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and Z
    value:

    Code:
    Type Point3Data
       x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
        Pt2 = Vtx.Item(t2)
        FacePt2(0) = Pt2.x
        FacePt2(1) = Pt2.y
        FacePt2(2) = Pt2.z
          Pt3 = Vtx.Item(t3)
          FacePt3(0) = Pt3.x
          FacePt3(1) = Pt3.y
          FacePt3(2) = Pt3.z
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can disprove
    this point....

    James


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b712d2_3@newsprd01...

    Hi, I have a very simple code that reads an ASCII file to extract Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.

  3. #3
    Yves Guest
    Thanks James,

    I used the collection because it's the only way I could find to store data,
    and not having to know in advance it's size.

    Putting it all in an array would mean, I need to got through the collections
    anyways.




    "James Belshan" <jlbelshan@yahoo.com> a écrit dans le message de news:
    41b73f96$1_1@newsprd01...
    The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI
    collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
    For i = 1 To CntTri - 1
    t1 = Tri1.Item(i)
    t2 = Tri2.Item(i)
    t3 = Tri3.Item(i)
    FacePt1(0) = VtxX.Item(t1)
    FacePt1(1) = VtxY.Item(t1)
    FacePt1(2) = VtxZ.Item(t1)
    FacePt2(0) = VtxX.Item(t2)
    FacePt2(1) = VtxY.Item(t2)
    FacePt2(2) = VtxZ.Item(t2)
    FacePt3(0) = VtxX.Item(t3)
    FacePt3(1) = VtxY.Item(t3)
    FacePt3(2) = VtxZ.Item(t3)
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
    If you can make collections of user-defined-types (I don't know about
    this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and Z
    value:

    Code:
    Type Point3Data
    x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
    Pt2 = Vtx.Item(t2)
    FacePt2(0) = Pt2.x
    FacePt2(1) = Pt2.y
    FacePt2(2) = Pt2.z
    Pt3 = Vtx.Item(t3)
    FacePt3(0) = Pt3.x
    FacePt3(1) = Pt3.y
    FacePt3(2) = Pt3.z
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can
    disprove
    this point....

    James


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b712d2_3@newsprd01...


    Hi, I have a very simple code that reads an ASCII file to extract Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.


  4. #4
    Yves Guest
    Hi James,

    After knowing that the collections might be part of my problem, I created
    array way bigger than needed, and the 5min file now opens in less than 20
    sec.


    Thanks.



    "James Belshan" <jlbelshan@yahoo.com> a écrit dans le message de news:
    41b73f96$1_1@newsprd01...
    The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI
    collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
    For i = 1 To CntTri - 1
    t1 = Tri1.Item(i)
    t2 = Tri2.Item(i)
    t3 = Tri3.Item(i)
    FacePt1(0) = VtxX.Item(t1)
    FacePt1(1) = VtxY.Item(t1)
    FacePt1(2) = VtxZ.Item(t1)
    FacePt2(0) = VtxX.Item(t2)
    FacePt2(1) = VtxY.Item(t2)
    FacePt2(2) = VtxZ.Item(t2)
    FacePt3(0) = VtxX.Item(t3)
    FacePt3(1) = VtxY.Item(t3)
    FacePt3(2) = VtxZ.Item(t3)
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
    If you can make collections of user-defined-types (I don't know about
    this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and Z
    value:

    Code:
    Type Point3Data
    x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
    Pt2 = Vtx.Item(t2)
    FacePt2(0) = Pt2.x
    FacePt2(1) = Pt2.y
    FacePt2(2) = Pt2.z
    Pt3 = Vtx.Item(t3)
    FacePt3(0) = Pt3.x
    FacePt3(1) = Pt3.y
    FacePt3(2) = Pt3.z
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can
    disprove
    this point....

    James


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b712d2_3@newsprd01...


    Hi, I have a very simple code that reads an ASCII file to extract Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.


  5. #5
    Laurie Comerford Guest
    Hi,

    If the file lines are of constant length, you can compute the number of
    lines from the file size and dimension your array accordingly.

    Alternatively, you may be able to open the file read it to count the number
    of lines, close the file, dimension the array and then reopen the file for
    reading.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b741f2_1@newsprd01...
    Thanks James,

    I used the collection because it's the only way I could find to store
    data,
    and not having to know in advance it's size.

    Putting it all in an array would mean, I need to got through the
    collections
    anyways.




    "James Belshan" <jlbelshan@yahoo.com> a écrit dans le message de news:
    41b73f96$1_1@newsprd01...
    The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI
    collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
    For i = 1 To CntTri - 1
    t1 = Tri1.Item(i)
    t2 = Tri2.Item(i)
    t3 = Tri3.Item(i)
    FacePt1(0) = VtxX.Item(t1)
    FacePt1(1) = VtxY.Item(t1)
    FacePt1(2) = VtxZ.Item(t1)
    FacePt2(0) = VtxX.Item(t2)
    FacePt2(1) = VtxY.Item(t2)
    FacePt2(2) = VtxZ.Item(t2)
    FacePt3(0) = VtxX.Item(t3)
    FacePt3(1) = VtxY.Item(t3)
    FacePt3(2) = VtxZ.Item(t3)
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
    If you can make collections of user-defined-types (I don't know about
    this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and
    Z
    value:

    Code:
    Type Point3Data
    x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
    Pt2 = Vtx.Item(t2)
    FacePt2(0) = Pt2.x
    FacePt2(1) = Pt2.y
    FacePt2(2) = Pt2.z
    Pt3 = Vtx.Item(t3)
    FacePt3(0) = Pt3.x
    FacePt3(1) = Pt3.y
    FacePt3(2) = Pt3.z
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can
    disprove
    this point....

    James


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b712d2_3@newsprd01...


    Hi, I have a very simple code that reads an ASCII file to extract
    Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow
    to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.




  6. #6
    James Belshan Guest
    Putting it all in an array would mean, I need to got through the
    collections
    anyways.
    Yes, but you'd be going through them only one time apiece, before you start
    looping, to copy them into an array. This would go quickly, especially with
    a For...Each loop. I think it's repeated diving into them for a specific
    item that gets so slow.

    I see from your other post that you found a quick solution... that's good.

    If you still wanted to use collections to input from the files, you could
    use a dynamic array and then re-size it using the collections .Count
    property before copying from the collection.

    James

  7. #7
    Tony Burba Guest
    You can refine this a bit by tracking the highest item in the array as it
    fills, then redimensioning it to that number after you've filled the array
    as far as it will go.


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b74f0c$1_2@newsprd01...
    Hi James,

    After knowing that the collections might be part of my problem, I created
    array way bigger than needed, and the 5min file now opens in less than 20
    sec.


    Thanks.



    "James Belshan" <jlbelshan@yahoo.com> a écrit dans le message de news:
    41b73f96$1_1@newsprd01...
    The collections are the slow part of your code.

    Here's moderate improvement, by not having to reference the TRI
    collections
    so often.

    Code:
    Dim t1 As Long, t2 As Long, t3 As Long
    For i = 1 To CntTri - 1
    t1 = Tri1.Item(i)
    t2 = Tri2.Item(i)
    t3 = Tri3.Item(i)
    FacePt1(0) = VtxX.Item(t1)
    FacePt1(1) = VtxY.Item(t1)
    FacePt1(2) = VtxZ.Item(t1)
    FacePt2(0) = VtxX.Item(t2)
    FacePt2(1) = VtxY.Item(t2)
    FacePt2(2) = VtxZ.Item(t2)
    FacePt3(0) = VtxX.Item(t3)
    FacePt3(1) = VtxY.Item(t3)
    FacePt3(2) = VtxZ.Item(t3)
    Set Obj3DFace = ThisDrawing.ModelSpace.Add3DFace(FacePt1, FacePt2,
    FacePt3, FacePt1)
    Next
    If you can make collections of user-defined-types (I don't know about
    this),
    you could further reduce the number of calls to collections by having a
    collection of UDT's so a single call to the collection gets an X,Y, and Z
    value:

    Code:
    Type Point3Data
    x As Double:  y As Double:  z As Double
    End Type
    Dim Pt3 as Point3Data
    
    Pt2 = Vtx.Item(t2)
    FacePt2(0) = Pt2.x
    FacePt2(1) = Pt2.y
    FacePt2(2) = Pt2.z
    Pt3 = Vtx.Item(t3)
    FacePt3(0) = Pt3.x
    FacePt3(1) = Pt3.y
    FacePt3(2) = Pt3.z
    Lastly, the quickest code, IMO, would be to copy your collections into
    arrays before running your loop. Using arrays would be fast with 11000
    items. I know arrays are going out of style, so maybe someone can
    disprove
    this point....

    James


    "Yves" <EvenHere@ThereIsTooMuchSpam.com> wrote in message
    news:41b712d2_3@newsprd01...


    Hi, I have a very simple code that reads an ASCII file to extract
    Points,
    and triangles formed with the points.

    The file I'm working on has about 11000 triangles that I want to form
    3dFaces with.
    (in case someone knows this product I read a Gocad file, which is slow
    to
    DXFOUT)

    First I load all the points into a collection, then all the triangles.
    I use this code to retreive the triangles and create them, but it takes
    about 5 min on a 1.5Gb Ram, 2.4Mhz computer.

    The ASCII file is read in about 2 seconds.

    Someone can help me speed up this thing.




Similar Threads

  1. Too slow VB6
    By NYacad in forum VBA
    Replies: 0
    Last Post: 09-19-2005, 08:07 PM
  2. Slow down
    By James in forum SolidWorks
    Replies: 17
    Last Post: 05-30-2005, 01:10 AM
  3. Slow Plotting
    By Lakecod in forum Printing
    Replies: 0
    Last Post: 04-01-2005, 02:31 PM
  4. why is CCAR so slow?
    By S. Badel in forum Cadence
    Replies: 11
    Last Post: 03-11-2005, 02:05 AM
  5. autocad slow to do anything
    By jrochte in forum AutoCAD
    Replies: 5
    Last Post: 11-16-2004, 07:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other forums: Access Forum - Microsoft Office Forum - Exchange Server Forum