Extracting binary occupancy map from Autocad

Extracting binary occupancy map from Autocad

celebihaluk36
Explorer Explorer
1,575 Views
9 Replies
Message 1 of 10

Extracting binary occupancy map from Autocad

celebihaluk36
Explorer
Explorer

I have a very dummy question. I am a newbie in Autocad.

 

- I have a 3D drawing of indoor / outdoor environment.  

 

- From this drawing, I want to build  a 3D matrix whose elements are either 0 or 1. I refer this matrix as "binary occupancy matrix" . So, for given (x,y,z) coordinate in the 3D drawing, binary occupancy matrix has either 0 or 1 value, where 0 represents empty/vacant volume, and 1 represents that solid volume. 

 

- My goal is to reduce a detailed 3D drawing into a simple matrix consisting of 0s and 1s. Is there any way to do this in Autocad?

 

- I appreciate your answers/comments

0 Likes
Accepted solutions (1)
1,576 Views
9 Replies
Replies (9)
Message 2 of 10

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I want to build a 3D matrix whose elements are either 0 or 1

So you create an array of points and for each point you want to know if it's inside a 3D-Solid or outside .. did I understand this correct?

If so ... programming is needed, there does not exist any OOTB function in AutoCAD.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 10

leeminardi
Mentor
Mentor

One approach would be to write a program that does a Boolean intersect of an object smaller than the grid resolution of the array of points with the solid model of the full object.  If the result is positive then the "point" is inside the shape.

 

Another approach would be to send a ray out from the point under consideration and count the number of intersections with the object's surfaces.  If the number is odd then the point is inside otherwise it is outside.

lee.minardi
0 Likes
Message 4 of 10

celebihaluk36
Explorer
Explorer

Similar to array but actually, it will be 3 dimensional matrix. For example, if total volume of drawing has dimensions of 3m x 5m x2 m in x, y, z plane. My binary occupancy matrix will have 3 x 5 x 2 = 30 elements (either 0 or 1). This is for 1m x1m x1m unit volume resolution. Resolution is not actually important for now. I am just giving an example. 

 

If programming is needed, what would be your approach? thanks for the comment by the way

0 Likes
Message 5 of 10

leeminardi
Mentor
Mentor

Check out vla-CheckInterference.  You could use it in a triple nested loop to move a box (1m per side as in your example) within the bounds of the subject object. The most inner loop would move the box in x, the next outer loop in y and the outside loop in Z.

A check interference would be done inside the inner most loop.  If the result is not nil then you have a 1 for that element of your 3D array and you can record the location in your matrix.  You would then do an undo before moving the box to the next location to be checked.  After the three loops have run through their range of values you would have the 3D "binary map".

 

 

lee.minardi
0 Likes
Message 6 of 10

celebihaluk36
Explorer
Explorer

 From my understanding in the function should take following inputs:

RetVal = object.CheckInterference(Object, CreateInterferenceSolid, SolidsInterfere)

 Object: original drawing from which binary map to be extracted

CreateInterferenceSolid: a cubic volume (i.e. 1mx1mx1m) placed on particular x,y,z. 

SolidsInterfere: 'true'

Retval: interference object: (1) non-empty; (0) void, no-object

 

And  iterate this function over all x,y,z in loop?

 

 

 

 

 

0 Likes
Message 7 of 10

leeminardi
Mentor
Mentor
Accepted solution

I have limited vlisp experience but took a stab at creating the program.

The following is a work-in-progress but it does create an ASCII file of 1's, and 0's for one pass in the x direction.

To use it create a box of desired size (e.g., one unit square) and an object to analyze .  Place the box outside of the object being analyzed such that when it moves in the x direction it will pass through the object.  The program runs one pass in x.   It could be expanded with additional loops to index in the y and z direction.  I stopped here to see if this is on the right track.

 

Here's a sample output of one row for passing the red box through the white shape.

image.png

(defun c:bin (/ fname s i n v c cx cy cz)
; lrm version 1.0 1/18/2020
; steps a box sequentially through a solid and creates a file
; noting when the box and solid overlap
; - limited to one row in x 
  (vl-load-com)
  (setq fname (getfiled "Filename" "" "txt" 1))
  (setq fname (open fname "w"))
  (write-line "row 1" fname)
  (setq obj (car (entsel "\nSelect object for analysis.")))
  (setq box (car (entsel "\nSelect box.")))
  (setq delta (getreal "\nEnter step size."))
  (setq nstepsx (getint "\nEnter number of steps in x"))
  (setq aline "")
  (setq	obj1 (vlax-ename->vla-object obj)
	box1 (vlax-ename->vla-object box)
  )
  (setq i 0)
  (setq	p1 '(0 0 0)
	p2 (list delta 0 0)
  )
	(while (< i nstepsx)
	  (setq
	    solidObj
	     (vla-CheckInterference obj1 box1 :vlax-false :vlax-false)
	  )
	  (if solidObj
	    (setq aline (strcat aline "1"))	; yes, intersection
	    (setq aline (strcat aline "0"))	; no intersection
	  )
	  (setq i (+ i 1))
	  (vla-move box1 (vlax-3D-point p1) (vlax-3D-point p2))
	)					; end while
  (write-line aline fname)
  (close fname)
  (princ)
)

The program creates solids for each of the checks which you probably don't want.

lee.minardi
Message 8 of 10

celebihaluk36
Explorer
Explorer

plenty of useful information. Thank you very much. 

0 Likes
Message 9 of 10

f20150458
Community Visitor
Community Visitor

Hello @celebihaluk36 

 

Did you figure out how to do this along all 3 dimensions? If so, can you share your script?

 

Thanks!

0 Likes
Message 10 of 10

celebihaluk36
Explorer
Explorer
I did the project in Rhinoceros. It is useful for large maps.

However approach is almost the same except


import rhinoscriptsyntax as rs
Arr_1_0 = rs.BooleanIntersection(obj, BoxID, False)


intead of vla-CheckInterference obj1 box1 :vlax-false :vlax-false in
Autocad
0 Likes