Bitmap.hh 4.01 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Will Schroeder's avatar
Will Schroeder committed
4
5
6
7
8
  Module:    Bitmap.hh
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Ken Martin's avatar
Ken Martin committed
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

Copyright (c) 1993-1995 Ken Martin, Will Schroeder, Bill Lorensen.

This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
The following terms apply to all files associated with the software unless
explicitly disclaimed in individual files. This copyright specifically does
not apply to the related textbook "The Visualization Toolkit" ISBN
013199837-4 published by Prentice Hall which is covered by its own copyright.

The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is included
verbatim in any distributions. Additionally, the authors grant permission to
modify this software and its documentation for any purpose, provided that
such modifications are not distributed without the explicit consent of the
authors and that existing copyright notices are retained in all copies. Some
of the algorithms implemented by this software are patented, observe all
applicable patent law.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Will Schroeder's avatar
Will Schroeder committed
38
39
40
41
42
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.


=========================================================================*/
Ken Martin's avatar
Ken Martin committed
43
// .NAME vtkBitmap - scalar data in bitmap form
Will Schroeder's avatar
Will Schroeder committed
44
// .SECTION Description
Ken Martin's avatar
Ken Martin committed
45
// vtkBitmap is a concrete implementation of vtkScalars. Scalars are
Will Schroeder's avatar
Will Schroeder committed
46
47
// represented using a packed character array of (0,1) values.

Ken Martin's avatar
Ken Martin committed
48
49
#ifndef __vtkBitmap_h
#define __vtkBitmap_h
Will Schroeder's avatar
Will Schroeder committed
50
51
52
53

#include "CoScalar.hh"
#include "BArray.hh"

Ken Martin's avatar
Ken Martin committed
54
class vtkBitmap : public vtkColorScalars 
Will Schroeder's avatar
Will Schroeder committed
55
56
{
public:
Ken Martin's avatar
Ken Martin committed
57
58
59
60
  vtkBitmap() {};
  ~vtkBitmap() {};
  vtkBitmap(const vtkBitmap& fs) {this->S = fs.S;};
  vtkBitmap(const int sz, const int ext=1000):S(sz,ext){};
Will Schroeder's avatar
Will Schroeder committed
61
62
  int Allocate(const int sz, const int ext=1000) {return this->S.Allocate(sz,ext);};
  void Initialize() {this->S.Initialize();};
Ken Martin's avatar
Ken Martin committed
63
  char *GetClassName() {return "vtkBitmap";};
Will Schroeder's avatar
Will Schroeder committed
64

Ken Martin's avatar
Ken Martin committed
65
66
  // vtkScalar interface
  vtkScalars *MakeObject(int sze, int ext=1000);
Will Schroeder's avatar
Will Schroeder committed
67
68
69
70
  int GetNumberOfScalars() {return (this->S.GetMaxId()+1);};
  void Squeeze() {this->S.Squeeze();};

  // miscellaneous
Ken Martin's avatar
Ken Martin committed
71
72
  vtkBitmap &operator=(const vtkBitmap& fs);
  void operator+=(const vtkBitmap& fs) {this->S += fs.S;};
Will Schroeder's avatar
Will Schroeder committed
73
  void Reset() {this->S.Reset();};
74
75
  unsigned char *GetPtr(const int id);
  unsigned char *WritePtr(const int id, const int number);
Will Schroeder's avatar
Will Schroeder committed
76

Ken Martin's avatar
Ken Martin committed
77
  // vtkColorScalar interface.
Will Schroeder's avatar
Will Schroeder committed
78
  unsigned char *GetColor(int id);
Will Schroeder's avatar
Will Schroeder committed
79
80
81
82
  void GetColor(int id, unsigned char rgba[4]);
  void SetColor(int id, unsigned char rgba[4]);
  void InsertColor(int id, unsigned char rgba[4]);
  int InsertNextColor(unsigned char rgba[4]);
Will Schroeder's avatar
Will Schroeder committed
83
84

protected:
Ken Martin's avatar
Ken Martin committed
85
  vtkBitArray S;
Will Schroeder's avatar
Will Schroeder committed
86
87
};

88
89
90
// Description:
// Get pointer to byte containing bit in question. You will have to decompose
// byte to obtain appropriate bit value.
Ken Martin's avatar
Ken Martin committed
91
inline unsigned char *vtkBitmap::GetPtr(const int id)
92
93
94
95
96
97
98
99
{
  return this->S.GetPtr(id);
}

// Description:
// Get pointer to data. Useful for direct writes into object. MaxId is bumped
// by number (and memory allocated if necessary). Id is the locaation you 
// wish to write into; number is the number of rgba colors to write.
Ken Martin's avatar
Ken Martin committed
100
inline unsigned char *vtkBitmap::WritePtr(const int id, const int number)
101
102
103
104
{
  return this->S.WritePtr(id,number);
}

Will Schroeder's avatar
Will Schroeder committed
105
#endif