| 
        
          | 
              
                | Author |  Topic  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  14:33:14     
 |  
                      | I have a rough time trying to convert the iekbox code (Looks like it's becoming obsolete) to a polyline. 
 This is the code i use.
 ImageEnVect.AddNewObject(iekBOX,
 Rect(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(i) +
 '_Left').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00' +
 IntToStr(i) + '_Top').AsInteger,
 Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(i) +
 '_Right').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00'
 + IntToStr(i) + '_Bottom').AsInteger), Mainform.PenColor.colorvalue);
 
 I tried that but I guess that is not it :)
 
 SetLength(iShapePoints, 4);
 iShapePoints[0] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Left').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Top').AsInteger);
 iShapePoints[1] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Top').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Right').AsInteger);
 iShapePoints[2] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Right').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Bottom').AsInteger);
 iShapePoints[3] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Bottom').AsInteger, Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Left').AsInteger);
 ilayer := Mainform.ImageEnVect.LayersAdd(ielkPolyline);
 TIEPolylineLayer(Mainform.ImageEnVect.Layers[ilayer]).LineWidth := 3;
 TIEPolylineLayer(Mainform.ImageEnVect.Layers[ilayer]).LineColor := clred;
 TIEPolylineLayer(Mainform.ImageEnVect.Layers[ilayer]).PolylineClosed := True;
 
 TIEPolylineLayer(Mainform.ImageEnVect.Layers[ilayer]).SetPoints(iShapePoints, True);
 Mainform.ImageEnVect.Update();
 
 Any guru out there that can help me?
 Thanks
 
 |  |  
                | xequte
      
 
                39218 Posts |  |  
                | xequte
      
 
                39218 Posts |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  14:53:41     
 |  
                      | The values are in a nexusDB database. they are the coordinates of each square to create a template. So they are the corner coordinates of the box. |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  14:59:19     
 |  
                      | Yes, the copyallobjects should work but i am trying to convert all the code as it looks like imageenvect is becoming obsolete. |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 29 2018 :  15:02:36     
 |  
                      | > corner coordinates of the box 
 Relative to what? The bitmap, the screen or some range?
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  15:05:29     
 |  
                      | Yes, i use bitmap coordinates of the background image. The boxes create a template. then i average the grayscale values inside each box. |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 29 2018 :  15:06:56     
 |  
                      | Hi 
 Then it should work if you use:
 
 TIEPolylineLayer(Mainform.ImageEnVect.Layers[ilayer]).SetPoints(iShapePoints, True, iepbBitmap);
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 29 2018 :  15:12:00     
 |  
                      | So your code would be something like: 
 
SetLength(ShapePoints, 4);
ShapePoints[0] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Left').AsInteger,
                        Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Top').AsInteger);
ShapePoints[1] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Top').AsInteger,
                        Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Right').AsInteger);
ShapePoints[2] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Right').AsInteger,
                        Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Bottom').AsInteger);
ShapePoints[3] := Point(Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Bottom').AsInteger,
                        Embeddeddm.nxTable_Tablet.FieldByName('Square00' + IntToStr(1) + '_Left').AsInteger);
Mainform.ImageEnVect.LayersAdd(ielkPolyline);
polyLayer := TIEPolylineLayer(Mainform.ImageEnVect.CurrentLayer);
polyLayer.LineWidth := 3;
polyLayer.LineColor := clRed;
polyLayer.SetPoints(ShapePoints, True);
Mainform.ImageEnVect.Update();
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  16:51:30     
 |  
                      | That does not work. it does not give me a square.I get a weird shape. I looked again at the rect function. the rect function gives me 2 points. the top left and the bottom right. these are the coordinates i have. so can i draw a square with only 2 Tpoints using polyline ? 
 |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 29 2018 :  17:32:32     
 |  
                      | Hi 
 Naturally, a rectangle requires 4 points, which you can generate from the Top,Left and Bottom,Right coordinates.
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 29 2018 :  18:35:18     
 |  
                      | No, this is not what i meant :) rect function only give you 2 points. the top/left (X,Y) that is the first point and the bottom right (X,Y) that is the second point. i have 4 values, they are X,Y for the first point and X,Y for the second point. so you really need only 2 points to draw a rectangle. can polyline do that ? |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 29 2018 :  19:49:23     
 |  
                      | Hi 
 A Polyline layer, by nature, requires an array of points (i.e. the polyline layer doesn't know what the shape is). So for a rect (given you have leftX,topY and rightX,bottomY) the four points would be:
 
 leftX,topY
 rightX,topY
 rightX,bottomY
 leftX,bottomY
 
 Otherwise you can use a TIEShapeLayer with a rectangle shape:
 
 ImageEnView1.LayersAdd( iesRectangle, Rect(leftX, topY, rightX, bottomY), clRed, 3, clNone );
 
 https://www.imageen.com/help/TImageEnView.LayersAdd.html
 
 Nigel
 Xequte Software
 www.imageen.com
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 30 2018 :  09:32:27     
 |  
                      | Thank you Nigel, that works. But before I strat modifying all my code, i would like to know if the following code will still work. What i have is an image with some gray patches. i create boxes in these patches and i average the gray values. Now that i use layers, i guess i can merge all layers or maybe not before i run the following command. if i merge all layers, do they rasterize ?
 This is what i run right now.
 
 Mainform.ImageEnVect.Select(Mainform.ImageEnVect.ObjLeft[i], Mainform.ImageEnVect.ObjTop[i], Mainform.ImageEnVect.ObjLeft[i] + Mainform.ImageEnVect.ObjWidth[i], Mainform.ImageEnVect.ObjTop[i] + Mainform.ImageEnVect.ObjHeight[i], iespReplace);
 Mainform.Calibration.Select((i * 100), 0, (i * 100) + 100, 100, iespReplace);
 Mainform.Calibration.Proc.Fill(Mainform.ImageEnVect.Proc.CalcAverageRGB());
 
 Best
 Pierre
 |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 30 2018 :  19:00:51     
 |  
                      | Hi Pierre 
 It should be something like:
 
 
// Select in background layer the area of layer 1
ImageEnView1.LayersCurrent := 0;
ImageEnView1.SelectionBase := iesbClientArea;
lyr1Rect := ImageEnView1.ClientAreaBox;
ImageEnView1.Select( lyr1Rect.Left, lyr1Rect.Top, lyr1Rect.Right, lyr1Rect.Bottom );
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 30 2018 :  19:26:55     
 |  
                      | I see. so i would have to go through each layers. That should work. I will try to code something small and see what I get. Thank you Nigel. Best
 Pierre
 
 I may have to look at clientareabox though. if i have 2 rectangular polyline in one layer, how do i differentiate one from another ?
 Also, if i merge all, do they all rasterize or could i keep all the polylines in one layer ? that may not be posible though. just thinking as i am typing.
 |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 30 2018 :  19:47:26     
 |  
                      | > I may have to look at clientareabox though. if i have 2 rectangular polyline > in one layer, how do i differentiate one from another ?
 
 ClientAreaBox returns the area of the whole layer (rectangular area that fits all polylines within.
 
 > Also, if i merge all, do they all rasterize or could i keep all the polylines
 > in one layer ?
 
 Two polyline layers cannot be merged into one polyline layer. As a polyline layer supports only one "line"
 
 Merging converts the polyline layer into a bitmap.
 
 
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 30 2018 :  19:51:31     
 |  
                      | ok..will play with it tomorrow. thanks for the code sample... something i noticed when i created all the polyline layers is sometimes when i click on one layer in the thumbnail of imageenmview, i get 2 selected. for example layer 2 and 5 get selected when i click on layer 2. not sure what is happening.
 will try a clean project from scratch in the morning.
 |  
                      |  |  |  
                | xequte
      
 
                39218 Posts | 
                    
                      |  Posted - Nov 30 2018 :  20:05:38     
 |  
                      | Try to create a sequence to reproduce the bug and let me know the steps. 
 
 
 Nigel
 Xequte Software
 www.imageen.com
 
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Nov 30 2018 :  21:00:03     
 |  
                      | i will. i think i need to start from scratch first to see if i can reproduce it. right now, i am mixing vectors and polylines. Best
 |  
                      |  |  |  
                | pierrotsc
    
 
                USA499 Posts
 | 
                    
                      |  Posted - Dec 01 2018 :  13:43:45     
 |  
                      | Ok, Nigel, i think i am getting there but it is not working. i modified the layers demo but in a nutshell, this is what i am doing. i am loading an image, then i press a button that adds 3 polyline layers. They are 100x100 squares. Then i am trying to select the layer 1 size, and average the points of the background within this selection. nothing is happening. here's the simple code ImageEnView1.LayersAdd(iesRectangle, Rect(5, 5, 100, 100), clRed, 3, clNone);
 ImageEnView1.Update();
 ImageEnView1.LayersAdd(iesRectangle, Rect(105, 5, 205, 100), clRed, 3, clNone);
 ImageEnView1.Update();
 ImageEnView1.LayersAdd(iesRectangle, Rect(210, 5, 310, 100), clRed, 3, clNone);
 ImageEnView1.Update();
 
 ImageEnView1.Deselect;
 ImageEnView1.LayersCurrent := 0;
 ImageEnView1.SelectionBase := iesbClientArea;
 lyr1Rect := ImageEnView1.Layers[1].ClientAreaBox;
 ImageEnView1.Select(lyr1Rect.Left, lyr1Rect.Top, lyr1Rect.Right, lyr1Rect.Bottom);
 ImageEnView1.Update();
 ImageEnView1.Proc.Fill(ImageEnView1.Proc.CalcAverageRGB());
 ImageEnView1.Update();
 
 Do you see what the issue is ?
 Thanks
 Best
 Pierre
 |  
                      |  |  |  
                
                |  Topic  |  |  |  |