Slow creating 3DFaces
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Slow creating 3DFaces

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
Yves
Guest





Posted: Wed Dec 08, 2004 7:42 pm    Post subject: Slow creating 3DFaces Reply with quote

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

Back to top
James Belshan
Guest





Posted: Wed Dec 08, 2004 10:53 pm    Post subject: Re: Slow creating 3DFaces Reply with quote

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...
Quote:


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.
Back to top
Yves
Guest





Posted: Wed Dec 08, 2004 11:03 pm    Post subject: Re: Slow creating 3DFaces Reply with quote

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...
Quote:
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.




Back to top
Yves
Guest





Posted: Wed Dec 08, 2004 11:59 pm    Post subject: Re: Slow creating 3DFaces Reply with quote

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...
Quote:
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.


Back to top
Laurie Comerford
Guest





Posted: Thu Dec 09, 2004 1:03 am    Post subject: Re: Slow creating 3DFaces Reply with quote

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...
Quote:
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.




Back to top
James Belshan
Guest





Posted: Thu Dec 09, 2004 2:53 am    Post subject: Re: Slow creating 3DFaces Reply with quote

Quote:

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
Back to top
Tony Burba
Guest





Posted: Fri Dec 10, 2004 5:16 am    Post subject: Re: Slow creating 3DFaces Reply with quote

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...
Quote:
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.




Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB