Decode encrypted ACIS data ACIS-REGION

;;; ACIS-REGION.LSP

;;; by Reini Urban, 12/1/98

;;; no warranties, given to the public domain.

;;; Extracts some REGION info from a 3DSOLID.

;;; Simple test functions, not very useful for apps but useful

;;; for playing with it. see the Acis SAT docs at www.spatial.com (in postscript)

;;; requires the AutoLISP STDLIB http://xarch.tu-graz.ac.at/autocad/stdlib/

;;; a region has no triangulation stored. we must better use 3dsout/3dsin

;;; or explode to get some faces.

;;; sample region data

;|

  34
  +---+29
  |   |
  |   +--+24
  |   25 |
  |      |
  +------+32
  35

header "106 36 1 0 "

0 "body $-1 $1 $-1 $-1 #" => to lump at 1

1 "lump $-1 $-1 $2 $0 #" => to shell (child) at 2 and body (parent) at 0

2 "shell $-1 $-1 $-1 $3 $1 #" => bounded (no next shell+subshell), face3, parent lump1

3 "face $-1 $-1 $4 $2 $-1 $5 forward double out #" =>loop4, in shell2, surface5

4 "loop $-1 $-1 $6 $3 #" => coeedge6

5 "plane-surface $-1 6.2211508759432341 6.0525378103691665 0 0 0 1 1 0 0 0 I I I I #"

6 "coedge $-1 $7 $8 $-1 $9 0 $4 $-1 #" => edge9

7 "coedge $-1 $10 $6 $-1 $11 0 $4 $-1 #" => edge11

8 "coedge $-1 $6 $12 $-1 $13 0 $4 $-1 #" => edge13

9 "edge $-1 $14 $15 $6 $16 0 #" => line v14-v15 (=p24-p25)

10 "coedge $-1 $17 $7 $-1 $18 0 $4 $-1 #" => edge18

11 "edge $-1 $15 $19 $7 $20 0 #" => line v15-v19 (=p25-p29)

12 "coedge $-1 $8 $17 $-1 $21 0 $4 $-1 #" => edge21

13 "edge $-1 $22 $14 $8 $23 0 #" => line v22-v14 (=p32-p24)

14 "vertex $-1 $9 $24 #" =p24

15 "vertex $-1 $9 $25 #" =p25

16 "straight-curve $-1 10.3919107277945 6.6328077489319801 0 -1 3.8791551863714972e-016 0 I I #"

17 "coedge $-1 $12 $10 $-1 $26 0 $4 $-1 #" => edge26

18 "edge $-1 $19 $27 $10 $28 0 #" => line v19-v27 (=p29-p34)

19 "vertex $-1 $11 $29 #" =p29

20 "straight-curve $-1 5.8126743888074337 6.6328077489319819 0 -4.3048961392706539e-016 1 0 I I #"

21 "edge $-1 $30 $22 $12 $31 0 #" => line v30-v22 (=p35-p32)

22 "vertex $-1 $21 $32 #" =p32

23 "straight-curve $-1 10.391910727794501 2.8288159400756316 0 -4.669717834997924e-016 1 0 I I #"

24 "point $-1 10.3919107277945 6.6328077489319801 0 #"

25 "point $-1 5.8126743888074337 6.6328077489319819 0 #"

26 "edge $-1 $27 $30 $17 $33 0 #" => line v27-v30 (=p34-p35)

27 "vertex $-1 $18 $34 #" =p34

28 "straight-curve $-1 5.8126743888074328 8.6959897420998882 0 -1 5.2965388415035719e-016 0 I I #"

29 "point $-1 5.8126743888074328 8.6959897420998882 0 #"

30 "vertex $-1 $26 $35 #" =p35

31 "straight-curve $-1 2.4588675112277691 2.8288159400756325 0 1 -1.1195935726724954e-016 0 I I #"

32 "point $-1 10.391910727794501 2.8288159400756316 0 #"

33 "straight-curve $-1 2.4588675112277691 8.6959897420998864 0 0 -1 0 I I #"

34 "point $-1 2.4588675112277691 8.6959897420998864 0 #"

35 "point $-1 2.4588675112277691 2.8288159400756325 0 #"

|;

(if (not std-remove-if-not) (load "stdlib"))
      

;;; accepts region ename,

;;; decode a region into segments, list of (p1 p2)

;;; returns just the boundary as segmentlist, no faces, no triangulation!

(defun acis-region (ele / acis pts vtx edges)
  (setq acis (cdr (mapcar 
    '(lambda (s) (decode (cdr s)))
     (std-remove-if-not 
       '(lambda (l) (= (car l) 1))
        (std-entget ele)))))
  (setq pts (mapcar 'acis->point acis))
  (setq vtx (mapcar 'acis->vertex acis))
  (setq edges (mapcar
   '(lambda (s / edge)
      (if (acis-edge-p s)
        (progn

(setq edge (acis->edge s)) ; v14-v15

           (list

(nth (car edge) vtx) ; p24

(nth (cadr edge) vtx))))) ; p25

    acis))
  (std-remove-if 'null
    (mapcar
     '(lambda (pl) 
        (if pl (list (nth (car pl) pts) 
                     (nth (cadr pl) pts))))
      edges)))

(defun acis-decode (s) ; decode an encrypted acis-string of dxf group 1

  (apply 'strcat
    (mapcar

'(lambda (c) ; decode one char

(cond ; by Owen Wengerd

          ((= c 32) " ")
          ((= c 86) "I")
          (T (chr (boole 6 c 95)))))
     (std-string->list s))))

(defun acis-point-p (s)
  (std-strcmp "point" s))
(defun acis-vertex-p (s)
  (std-strcmp "vertex" s))
(defun acis-edge-p (s)
  (std-strcmp "edge" s))

(defun acis->point (s)
  (if (acis-point-p s)
    (read (strcat "(" (substr (std-str-1 s) 10) ")"))))
(defun acis->vertex (s)
  (if (acis-vertex-p s)
    (acis-nth-pointer 3 s)))
(defun acis->edge (s)
  (if (acis-edge-p s)
    (list (acis-nth-pointer 2 s)(acis-nth-pointer 3 s))))
    
(defun acis-nth-pointer (i s)
  (repeat i (setq s (substr s (1+ (std-strpos "$" s)))))
  (atoi s))

(defun c:test ()
  (if (setq ele (entsel "pick REGION: "))
    (acis-region ele)))