It is currently Thu Oct 24, 2019 6:03 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: HELP! - how to do this with an array of data.
PostPosted: Wed Apr 02, 2014 7:47 pm 
Offline
User
User

Joined: Wed Dec 02, 2009 4:50 pm
Posts: 31
Location: Oklahoma City, OK
Okay, I've hit a dilema.

I need to store a series of polyline shapes that are defined as a list of x/y coordinates. These represent the locations of coordinates for each point in an irregular 2d shape. In VB, I was drawing a series of shapes and filling them with a color. It's for a mapping display showing buildings. Each building outline is drawn and then filled.

I had created a structure such as:
structure pts
x.f
y.f
endstructure

Define bldgs.pts(0)

Then, as I read the data file, "999" is used as a flag for the end of each segment.

I would read the datafile and continue to add the points to the bldgs() array until "999" was encountered".

In VB, I would then add the entire bldgs.pts() array to a collection called allpoints() say. So allpoints(0) would contain multiple copies of bldgs() with different sets of points.

I would then use For Each to draw the polyline segments of each building from the allpoints() collection.

How can I do this with Purebasic? I need an an array of a structured array; something like;

structure pts
x.f
y.f
endstructure

Define points.pts(0) ; first create the structure to hold the points.

Define bldgs().points ; then an array to hold the collection of points.

Here is the actual VB.NET code
Code:
Here is the actual VB.NET code

   Public gdiBLDGS As New Collection 'this is a collection of point arrays

        Dim Temppts(0) As PointF
        Dim x1 As Single
        Dim y1 As Single
        Dim ub As Int32
        Dim FileName$ = TowerPath + "\asde_bldgs.srq"
        ' Open file.
        FileOpen(1, FileName$, OpenMode.Input)
        ' Loop until end of file.
        ub = 0
        Do While Not EOF(1)
            ' Read line into variable.
            Input(1, x1)
            Input(1, y1)
            If x1 = 999 And y1 = 999 Then
                gdiBLDGS.Add(Temppts)
                ub = 0
                'clear the temppts array
                ReDim Temppts(0)
            Else
                ReDim Preserve Temppts(ub)
                Temppts(ub).X = x1 + 288.81145 '293.81145
                Temppts(ub).Y = Abs(y1 + -88.59055) '-91.59055)
                ub = ub + 1
            End If
        Loop
        FileClose(1)

So, any ideas of how to handle this would be appreciated.


Top
 Profile  
Reply with quote  
 Post subject: Re: HELP! - how to do this with an array of data.
PostPosted: Wed Apr 02, 2014 8:33 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3402
Location: New Zealand
something like this using lists would be easier

Code:
Structure pts
   x.f
   y.f
EndStructure   

Structure building
   List pts.pts()
EndStructure

Structure buildings
   List building.building()
EndStructure   

Global colbuildings.buildings()
InitializeStructure(@colbuildings,buildings)

Procedure readbuildings(file.s)
   Protected pts.pts,fn   
   
   fn = OpenFile(#PB_Any,file)
   If fn
      While Not Eof(fn)
         pts\x = ReadFloat(fn)
         pts\y = ReadFloat(fn)
         If Int(pts\x) = 999 And Int(pts\y) =999
            AddElement(colbuildings\building())
         Else
            AddElement(colbuildings\building()\pts())
            colbuildings\building()\pts()\x = pts\x
            colbuildings\building()\pts()\y = pts\y
         EndIf
      Wend
      CloseFile(fn)
   EndIf   
EndProcedure

Procedure plotbuilding()
   Protected x.f,y.f,x1.f,y1.f 
   
   ForEach colbuildings\building()
      ForEach colbuildings\building()\pts()
         x1 = x
         y2 = y
         x = colbuildings\building()\pts()\x
         y = colbuildings\building()\pts()\y 
         If Int(x1) <> 0 Or Int(y1) <> 0   
            ;plot
         EndIf   
      Next
      x1=0
      y1=0 
   Next
EndProcedure   




Top
 Profile  
Reply with quote  
 Post subject: Re: HELP! - how to do this with an array of data.
PostPosted: Wed Apr 02, 2014 10:11 pm 
Offline
User
User

Joined: Wed Dec 02, 2009 4:50 pm
Posts: 31
Location: Oklahoma City, OK
Thank you very much. I will give this a shot.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye