or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

analysis-algorithms.mdapplications.mdcolors-visual.mdcore-objects.mdfile-io.mdindex.mdplotting-visualization.mdshape-generation.mdtransformations-geometry.mdui-components.md

colors-visual.mddocs/

0

# Colors and Visual Properties

1

2

Color management system including color conversion functions, colormap application, palette generation, and visual styling utilities for enhancing 3D visualizations. This module provides comprehensive tools for managing the visual appearance of vedo objects.

3

4

## Capabilities

5

6

### Color Conversion and Management

7

8

Functions for converting between different color representations and managing color specifications.

9

10

```python { .api }

11

def get_color(rgb=None, hsv=None):

12

"""

13

Convert color specifications to RGB format.

14

15

Parameters:

16

- rgb: tuple, str, or int, optional

17

RGB color specification

18

- hsv: tuple, optional

19

HSV color specification

20

21

Returns:

22

tuple: RGB color values (0-1 range)

23

"""

24

25

def get_color_name(c):

26

"""

27

Get color name from RGB values.

28

29

Parameters:

30

- c: tuple or array-like

31

RGB color values

32

33

Returns:

34

str: Closest color name

35

"""

36

37

def hsv2rgb(hsv):

38

"""

39

Convert HSV color to RGB.

40

41

Parameters:

42

- hsv: list or tuple

43

HSV color values [hue, saturation, value]

44

45

Returns:

46

list: RGB color values

47

"""

48

49

def rgb2hsv(rgb):

50

"""

51

Convert RGB color to HSV.

52

53

Parameters:

54

- rgb: list or tuple

55

RGB color values

56

57

Returns:

58

list: HSV color values

59

"""

60

61

def rgb2hex(rgb):

62

"""

63

Convert RGB color to hexadecimal.

64

65

Parameters:

66

- rgb: list or tuple

67

RGB color values

68

69

Returns:

70

str: Hexadecimal color string

71

"""

72

73

def hex2rgb(hx):

74

"""

75

Convert hexadecimal color to RGB.

76

77

Parameters:

78

- hx: str

79

Hexadecimal color string

80

81

Returns:

82

list: RGB color values

83

"""

84

```

85

86

### Colormaps and Palettes

87

88

Functions for applying colormaps to scalar data and generating color palettes.

89

90

```python { .api }

91

def color_map(value, name="jet", vmin=None, vmax=None):

92

"""

93

Apply colormap to scalar values.

94

95

Parameters:

96

- value: float, array-like

97

Scalar value(s) to map

98

- name: str, default "jet"

99

Colormap name (matplotlib or vedo colormaps)

100

- vmin: float, optional

101

Minimum value for color mapping

102

- vmax: float, optional

103

Maximum value for color mapping

104

105

Returns:

106

tuple or array: RGB color(s) corresponding to input values

107

"""

108

109

def build_palette(color1, color2, n, hsv=True):

110

"""

111

Create color palette between two colors.

112

113

Parameters:

114

- color1: str or tuple

115

Starting color

116

- color2: str or tuple

117

Ending color

118

- n: int

119

Number of colors in palette

120

- hsv: bool, default True

121

Interpolate in HSV space instead of RGB

122

123

Returns:

124

numpy.ndarray: Array of RGB colors

125

"""

126

127

def build_lut(

128

colorlist,

129

vmin=None,

130

vmax=None,

131

below_color=None,

132

above_color=None,

133

nan_color=None,

134

below_alpha=None,

135

above_alpha=None,

136

nan_alpha=None,

137

interpolate=True

138

):

139

"""

140

Build lookup table for color mapping.

141

142

Parameters:

143

- colorlist: list

144

List of colors for the lookup table

145

- vmin: float, optional

146

Minimum scalar value

147

- vmax: float, optional

148

Maximum scalar value

149

- below_color: str or tuple, optional

150

Color for values below vmin

151

- above_color: str or tuple, optional

152

Color for values above vmax

153

- nan_color: str or tuple, optional

154

Color for NaN values

155

- below_alpha: float, optional

156

Alpha for below_color

157

- above_alpha: float, optional

158

Alpha for above_color

159

- nan_alpha: float, optional

160

Alpha for nan_color

161

- interpolate: bool, default True

162

Interpolate colors between control points

163

164

Returns:

165

vtkLookupTable: VTK lookup table object

166

"""

167

```

168

169

### Terminal Output and Printing

170

171

Enhanced printing functions with color and formatting support for terminal output.

172

173

```python { .api }

174

def printc(

175

*strings,

176

c=None,

177

bc=None,

178

bold=False,

179

italic=False,

180

blink=False,

181

underline=False,

182

strike=False,

183

dim=False,

184

invert=False,

185

box="",

186

end="\\n",

187

flush=False

188

):

189

"""

190

Print colored and formatted text to terminal.

191

192

Parameters:

193

- *strings: variable arguments

194

Text strings to print

195

- c: str or int, optional

196

Text color name or code

197

- bc: str or int, optional

198

Background color name or code

199

- bold: bool, default False

200

Use bold text

201

- italic: bool, default False

202

Use italic text

203

- blink: bool, default False

204

Use blinking text

205

- underline: bool, default False

206

Use underlined text

207

- strike: bool, default False

208

Use strikethrough text

209

- dim: bool, default False

210

Use dim text

211

- invert: bool, default False

212

Invert foreground/background colors

213

- box: str, default ""

214

Box style for text ("", "=", "-", etc.)

215

- end: str, default "\\n"

216

String appended after the last value

217

- flush: bool, default False

218

Forcibly flush the stream

219

"""

220

221

def printd(*strings, q=False):

222

"""

223

Print debug information with special formatting.

224

225

Parameters:

226

- *strings: variable arguments

227

Debug strings to print

228

- q: bool, default False

229

Suppress output if True

230

"""

231

```

232

233

### Visual Property Classes

234

235

Classes for managing advanced visual properties and lighting.

236

237

```python { .api }

238

class LightKit:

239

"""

240

Advanced lighting system for 3D scenes.

241

242

Parameters:

243

- key_light_intensity: float, default 1.0

244

Intensity of key light

245

- key_light_warmth: float, default 0.6

246

Warmth of key light color

247

- fill_light_intensity: float, default 0.3

248

Intensity of fill light

249

- fill_light_warmth: float, default 0.4

250

Warmth of fill light color

251

- back_light_intensity: float, default 0.1

252

Intensity of back light

253

- back_light_warmth: float, default 0.5

254

Warmth of back light color

255

"""

256

def __init__(

257

self,

258

key_light_intensity=1.0,

259

key_light_warmth=0.6,

260

fill_light_intensity=0.3,

261

fill_light_warmth=0.4,

262

back_light_intensity=0.1,

263

back_light_warmth=0.5

264

): ...

265

```

266

267

### Available Color Names and Colormaps

268

269

Predefined color names and colormap options available in vedo.

270

271

```python { .api }

272

# Common color names (subset of available colors)

273

COLOR_NAMES = [

274

"red", "green", "blue", "yellow", "cyan", "magenta", "white", "black",

275

"gray", "orange", "pink", "purple", "brown", "lime", "olive", "navy",

276

"teal", "silver", "gold", "crimson", "indigo", "violet", "turquoise",

277

"salmon", "khaki", "plum", "orchid", "tan", "coral", "azure", "ivory"

278

]

279

280

# Available colormaps (subset of available maps)

281

COLORMAPS = [

282

# Sequential colormaps

283

"viridis", "plasma", "inferno", "magma", "cividis",

284

"Blues", "Greens", "Reds", "Oranges", "Purples",

285

"hot", "cool", "spring", "summer", "autumn", "winter",

286

287

# Diverging colormaps

288

"coolwarm", "bwr", "seismic", "RdBu", "RdYlBu", "RdYlGn",

289

"Spectral", "PiYG", "PRGn", "BrBG", "PuOr", "RdGy",

290

291

# Qualitative colormaps

292

"Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Dark2",

293

"Accent", "tab10", "tab20", "tab20b", "tab20c",

294

295

# Special vedo colormaps

296

"jet", "rainbow", "terrain", "gist_earth", "ocean",

297

"flag", "prism", "hsv", "nipy_spectral", "gist_ncar"

298

]

299

```

300

301

## Usage Examples

302

303

```python

304

import vedo

305

import numpy as np

306

307

# Basic color specifications

308

sphere_red = vedo.Sphere(c='red')

309

sphere_rgb = vedo.Sphere(c=(0.2, 0.8, 0.3))

310

sphere_hex = vedo.Sphere(c='#ff5733')

311

312

# Color conversions

313

rgb_color = vedo.get_color('blue')

314

hex_color = vedo.rgb2hex([1, 0, 0])

315

hsv_color = vedo.rgb2hsv([0.5, 0.3, 0.8])

316

317

# Apply colormaps to data

318

x = np.linspace(0, 10, 100)

319

y = np.sin(x)

320

scalar_data = y + np.random.normal(0, 0.1, 100)

321

322

# Create mesh with scalar coloring

323

points = np.column_stack([x, y, np.zeros(100)])

324

mesh = vedo.Points(points)

325

mesh.cmap('viridis', scalar_data)

326

327

# Custom color palette

328

colors = vedo.build_palette('blue', 'red', 10)

329

multicolor_spheres = []

330

for i, color in enumerate(colors):

331

sphere = vedo.Sphere(pos=(i, 0, 0), c=color, r=0.3)

332

multicolor_spheres.append(sphere)

333

334

# Advanced colormap with custom lookup table

335

lut = vedo.build_lut(

336

['blue', 'cyan', 'yellow', 'red'],

337

vmin=0, vmax=1,

338

below_color='black',

339

above_color='white',

340

interpolate=True

341

)

342

343

# Apply to volume data

344

volume_data = np.random.rand(50, 50, 50)

345

volume = vedo.Volume(volume_data)

346

volume.cmap(lut)

347

348

# Enhanced terminal output

349

vedo.printc("Success!", c='green', bold=True)

350

vedo.printc("Warning:", c='yellow', bc='black', box='-')

351

vedo.printc("Error occurred", c='red', bold=True, blink=True)

352

353

# Debug printing

354

vedo.printd("Debug info:", np.mean(scalar_data), "processed")

355

356

# Advanced lighting setup

357

light_kit = vedo.LightKit(

358

key_light_intensity=1.2,

359

key_light_warmth=0.8,

360

fill_light_intensity=0.4

361

)

362

363

# Visualization with custom lighting

364

plt = vedo.Plotter()

365

plt.add(mesh)

366

plt.add_light_kit(light_kit)

367

plt.show()

368

369

# Color analysis

370

mesh_colors = mesh.colors() # Get current colors

371

color_names = [vedo.get_color_name(c) for c in mesh_colors[:5]]

372

vedo.printc("First 5 colors:", color_names, c='blue')

373

374

# Create gradient visualization

375

gradient_data = np.linspace(0, 1, 1000).reshape(20, 50)

376

gradient_image = vedo.Image(gradient_data)

377

gradient_image.cmap('rainbow')

378

vedo.show(gradient_image, title="Color Gradient")

379

```