Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

import director.applogic as app 

import director.objectmodel as om 

from director import cameraview 

 

import functools 

 

actionName = 'ActionColorizeLidar' 

 

 

 

def setVisProperties(obj, colorModeEnabled): 

 

    if colorModeEnabled: 

        alpha = 1.0 

        pointSize = 4.0 

        colorBy = 'rgb' 

    else: 

        alpha = 0.5 

        pointSize = 1.0 

        colorBy = None 

 

    obj.setProperty('Alpha', alpha) 

    obj.setProperty('Point Size', pointSize) 

 

 

def colorizePoints(polyData): 

    cameras = ['CAMERACHEST_RIGHT', 'CAMERACHEST_LEFT', 'CAMERA_LEFT'] 

    for camera in cameras: 

        cameraview.colorizePoints(polyData, camera) 

 

 

def colorizeSegmentationLidar(enabled): 

 

    obj = om.findObjectByName('pointcloud snapshot') 

    if not obj: 

        return 

 

    if enabled: 

        colorizePoints(obj.polyData) 

    else: 

        obj.polyData.GetPointData().RemoveArray('rgb') 

 

    setVisProperties(obj, enabled) 

 

 

_colorizeMapNames = ['HEIGHT_MAP_SCENE', 'SCANS_HALF_SWEEP'] 

 

def colorizeMapCallback(obj): 

    if obj and obj.getProperty('Name') in _colorizeMapNames: 

        colorizePoints(obj.polyData) 

        obj._updateColorByProperty() 

        obj.setProperty('Color By', 'rgb') 

 

 

def colorizeMaps(enabled): 

 

    if enabled: 

        om.findObjectByName('Map Server').source.colorizeCallback = colorizeMapCallback 

        for name in _colorizeMapNames: 

            colorizeMapCallback(om.findObjectByName(name)) 

    else: 

        om.findObjectByName('Map Server').source.colorizeCallback = None 

 

 

def colorizeMultisense(enabled): 

    obj = om.findObjectByName('Multisense') 

    if not obj: 

        return 

 

    setVisProperties(obj, enabled) 

    colorBy = 'Camera RGB' if enabled else 'Solid Color' 

    obj.setProperty('Color By', colorBy) 

 

 

def colorizeMapsOff(): 

    obj = om.findObjectByName('Map Server') 

    obj.source.colorizeCallback = None 

    alpha = 0.7 

    pointSize = 1.0 

    obj.setProperty('Alpha', alpha) 

    obj.setProperty('Point Size', pointSize) 

 

def onColorizeLidar(): 

 

    colorizeEnabled = app.getToolBarActions()[actionName].checked 

    colorizeMaps(colorizeEnabled) 

    colorizeMultisense(colorizeEnabled) 

    colorizeSegmentationLidar(colorizeEnabled) 

 

def initColorizeCallbacks(): 

 

    obj = om.findObjectByName('Multisense') 

    assert(obj) 

 

    def callback(): 

        colorizePoints(obj.model.polyDataObj.polyData) 

 

    obj.model.colorizeCallback = callback 

 

 

def init(): 

    action = app.getToolBarActions()[actionName] 

    action.connect(action, 'triggered()', onColorizeLidar) 

    initColorizeCallbacks()