Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

TexturePlacement Class Reference

This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to. More...

#include <texturePlacement.h>

Inheritance diagram for TexturePlacement:

TypedWritable TypedObject List of all members.

Public Member Functions

 TexturePlacement (TextureImage *texture, PaletteGroup *group)
 ~TexturePlacement ()
const string & get_name () const
 Returns the name of the texture that this placement represents.

TextureImageget_texture () const
 Returns the texture that this placement represents.

const TexturePropertiesget_properties () const
 Returns the grouping properties of the image.

PaletteGroupget_group () const
 Returns the group that this placement represents.

void add_egg (TextureReference *reference)
 Records the fact that a particular egg file is using this particular TexturePlacement.

void remove_egg (TextureReference *reference)
 Notes that a particular egg file is no longer using this particular TexturePlacement.

void mark_eggs_stale ()
 Marks all the egg files that reference this placement stale.

void set_dest (DestTextureImage *dest)
 Sets the DestTextureImage that corresponds to this texture as it was copied to the install directory.

DestTextureImageget_dest () const
 Returns the DestTextureImage that corresponds to this texture as it was copied to the install directory.

bool determine_size ()
 Attempts to determine the appropriate size of the texture for the given placement.

bool is_size_known () const
 Returns true if the texture's size is known, false otherwise.

OmitReason get_omit_reason () const
 Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.

int get_x_size () const
 Returns the size in the X dimension, in pixels, of the texture image as it must appear in the palette.

int get_y_size () const
 Returns the size in the Y dimension, in pixels, of the texture image as it must appear in the palette.

double get_uv_area () const
 Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.

bool is_placed () const
 Returns true if the texture has been placed on a palette image, false otherwise.

PaletteImageget_image () const
 Returns the particular PaletteImage on which the texture has been placed.

PalettePageget_page () const
 Returns the particular PalettePage on which the texture has been placed.

int get_placed_x () const
 Returns the X pixel at which the texture has been placed within its PaletteImage.

int get_placed_y () const
 Returns the Y pixel at which the texture has been placed within its PaletteImage.

int get_placed_x_size () const
 Returns the size in the X dimension, in pixels, of the texture image as it has been placed within the palette.

int get_placed_y_size () const
 Returns the size in the Y dimension, in pixels, of the texture image as it has been placed within the palette.

double get_placed_uv_area () const
 Returns the total area of the rectangle occupied by the UV minmax box, as it has been placed.

void place_at (PaletteImage *image, int x, int y)
 Assigns the texture to a particular position within the indicated PaletteImage.

void force_replace ()
 Removes the texture from its particular PaletteImage, but does not remove it from the PaletteGroup.

void omit_solitary ()
 Sets the omit reason (returned by get_omit()) to OR_solitary, indicating that the palettized version of the texture should not be used because it is the only texture on a PaletteImage.

void not_solitary ()
 Indicates that the texture, formerly indicated as solitary, is now no longer.

bool intersects (int x, int y, int x_size, int y_size)
 Returns true if the particular position this texture has been assigned to overlaps the rectangle whose top left corner is at x, y and whose size is given by x_size, y_size, or false otherwise.

void compute_tex_matrix (LMatrix3d &transform)
 Stores in the indicated matrix the appropriate texture matrix transform for the new placement of the texture.

void write_placed (ostream &out, int indent_level=0)
 Writes the placement position information on a line by itself.

bool is_filled () const
 Returns true if the texture has been filled (i.e.

void mark_unfilled ()
 Marks the texture as unfilled, so that it will need to be copied into the palette image again.

void fill_image (PNMImage &image)
 Fills in the rectangle of the palette image represented by the texture placement with the image pixels.

void flag_error_image (PNMImage &image)
 Sets the rectangle of the palette image represented by the texture placement to red, to represent a missing texture.

virtual void write_datagram (BamWriter *writer, Datagram &datagram)
 Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.

virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Called after the object is otherwise completely read from a Bam file, this function's job is to store the pointers that were retrieved from the Bam file for each pointer object written.

virtual TypeHandle get_type () const
virtual void finalize ()
virtual TypeHandle force_init_type (void)
int get_type_index () const
bool is_of_type (TypeHandle handle) const
bool is_exact_type (TypeHandle handle) const

Static Public Member Functions

void register_with_read_factory ()
 Registers the current object as something that can be read from a Bam file.

TypeHandle get_class_type ()
void init_type ()

Static Public Attributes

TypedWritable *const Null

Protected Member Functions

void fillin (DatagramIterator &scan, BamReader *manager)
 Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().


Static Protected Member Functions

TypedWritablemake_TexturePlacement (const FactoryParams &params)
 This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.


Private Types

typedef pset< TextureReference * > References

Private Member Functions

 TexturePlacement ()
 The default constructor is only for the convenience of the Bam reader.

void compute_size_from_uvs (const TexCoordd &min_uv, const TexCoordd &max_uv)
 A support function for determine_size(), this computes the appropriate size of the texture in pixels based on the UV coverage (as well as on the size of the source texture).


Private Attributes

TextureImage_texture
PaletteGroup_group
PaletteImage_image
DestTextureImage_dest
bool _has_uvs
bool _size_known
TexturePosition _position
bool _is_filled
TexturePosition _placed
OmitReason _omit_reason
References _references
int _num_references

Static Private Attributes

TypeHandle _type_handle

Detailed Description

This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.

Definition at line 59 of file texturePlacement.h.


Member Typedef Documentation

typedef pset<TextureReference *> TexturePlacement::References [private]
 

Definition at line 126 of file texturePlacement.h.


Constructor & Destructor Documentation

TexturePlacement::TexturePlacement  )  [private]
 

The default constructor is only for the convenience of the Bam reader.

Definition at line 51 of file texturePlacement.cxx.

References _is_filled, _omit_reason, and OR_none.

TexturePlacement::TexturePlacement TextureImage texture,
PaletteGroup group
 

Definition at line 70 of file texturePlacement.cxx.

References _omit_reason, and OR_unknown.

TexturePlacement::~TexturePlacement  ) 
 

Definition at line 97 of file texturePlacement.cxx.

References _group.


Member Function Documentation

void TexturePlacement::add_egg TextureReference reference  ) 
 

Records the fact that a particular egg file is using this particular TexturePlacement.

Definition at line 177 of file texturePlacement.cxx.

References _references, and TextureReference::mark_egg_stale().

Referenced by TextureReference::get_max_uv().

int TexturePlacement::complete_pointers TypedWritable **  p_list,
BamReader manager
[virtual]
 

Called after the object is otherwise completely read from a Bam file, this function's job is to store the pointers that were retrieved from the Bam file for each pointer object written.

The return value is the number of pointers processed from the list.

Reimplemented from TypedWritable.

Definition at line 1183 of file texturePlacement.cxx.

void TexturePlacement::compute_size_from_uvs const TexCoordd min_uv,
const TexCoordd max_uv
[private]
 

A support function for determine_size(), this computes the appropriate size of the texture in pixels based on the UV coverage (as well as on the size of the source texture).

Definition at line 1082 of file texturePlacement.cxx.

void TexturePlacement::compute_tex_matrix LMatrix3d &  transform  ) 
 

Stores in the indicated matrix the appropriate texture matrix transform for the new placement of the texture.

Definition at line 834 of file texturePlacement.cxx.

Referenced by omit_solitary().

bool TexturePlacement::determine_size  ) 
 

Attempts to determine the appropriate size of the texture for the given placement.

This is based on the UV range of the egg files that reference the texture. Returns true on success, or false if the texture size cannot be determined (e.g. the texture file is unknown).

After this returns true, get_x_size() and get_y_size() may safely be called.

Definition at line 286 of file texturePlacement.cxx.

References Palettizer::_round_fuzz, Palettizer::_round_unit, pal, and TexCoordd.

Referenced by PaletteGroup::is_preferred_over().

void TexturePlacement::fill_image PNMImage image  ) 
 

Fills in the rectangle of the palette image represented by the texture placement with the image pixels.

Definition at line 949 of file texturePlacement.cxx.

References _placed, _position, _references, and writer().

void TexturePlacement::fillin DatagramIterator scan,
BamReader manager
[protected]
 

Reads the binary data from the given datagram iterator, which was written by a previous call to write_datagram().

Reimplemented from TypedWritable.

Definition at line 1255 of file texturePlacement.cxx.

void TexturePlacement::flag_error_image PNMImage image  ) 
 

Sets the rectangle of the palette image represented by the texture placement to red, to represent a missing texture.

Definition at line 1051 of file texturePlacement.cxx.

References _is_filled, _num_references, _omit_reason, and _placed.

void TexturePlacement::force_replace  ) 
 

Removes the texture from its particular PaletteImage, but does not remove it from the PaletteGroup.

It will be re-placed when the PaletteGroup::place_all() is called.

Definition at line 736 of file texturePlacement.cxx.

Referenced by mark_eggs_stale().

TypeHandle TexturePlacement::get_class_type void   )  [inline, static]
 

Reimplemented from TypedWritable.

Definition at line 146 of file texturePlacement.h.

Referenced by mark_unfilled().

DestTextureImage * TexturePlacement::get_dest  )  const
 

Returns the DestTextureImage that corresponds to this texture as it was copied to the install directory.

Definition at line 257 of file texturePlacement.cxx.

References _references, TexCoordd, and x.

PaletteGroup * TexturePlacement::get_group  )  const
 

Returns the group that this placement represents.

Definition at line 162 of file texturePlacement.cxx.

References _references, and TextureReference::mark_egg_stale().

Referenced by PaletteGroup::get_dependency_order(), and EggFile::is_stale().

PaletteImage * TexturePlacement::get_image  )  const
 

Returns the particular PaletteImage on which the texture has been placed.

Definition at line 582 of file texturePlacement.cxx.

References _image, _is_filled, _omit_reason, _placed, _position, OR_none, x, and y.

Referenced by TextureImage::is_newer_than(), and PalettePage::place().

const string & TexturePlacement::get_name  )  const
 

Returns the name of the texture that this placement represents.

Definition at line 123 of file texturePlacement.cxx.

References _texture, and ImageFile::get_properties().

OmitReason TexturePlacement::get_omit_reason  )  const
 

Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.

Definition at line 484 of file texturePlacement.cxx.

References _image, is_placed(), nassertr, and NULL.

Referenced by PaletteGroup::get_page(), TextureImage::get_preferred_source(), and PalettePage::place_all().

PalettePage * TexturePlacement::get_page  )  const
 

Returns the particular PalettePage on which the texture has been placed.

Definition at line 598 of file texturePlacement.cxx.

References _image, _omit_reason, mark_eggs_stale(), NULL, OR_none, OR_working, and PaletteImage::unplace().

Referenced by PaletteGroup::get_dependency_order(), and PalettePage::place().

double TexturePlacement::get_placed_uv_area  )  const
 

Returns the total area of the rectangle occupied by the UV minmax box, as it has been placed.

See also get_uv_area().

Definition at line 688 of file texturePlacement.cxx.

References _image, _placed, and t.

Referenced by place_at().

int TexturePlacement::get_placed_x  )  const
 

Returns the X pixel at which the texture has been placed within its PaletteImage.

It is an error to call this unless is_placed() returns true.

Definition at line 616 of file texturePlacement.cxx.

References _omit_reason, is_placed(), mark_eggs_stale(), nassertv, and OR_solitary.

Referenced by PaletteImage::ClearedRegion::ClearedRegion(), place_at(), and PaletteImage::setup_shadow_image().

int TexturePlacement::get_placed_x_size  )  const
 

Returns the size in the X dimension, in pixels, of the texture image as it has been placed within the palette.

Definition at line 652 of file texturePlacement.cxx.

References _placed, TexturePosition::_x, TexturePosition::_x_size, TexturePosition::_y, TexturePosition::_y_size, is_placed(), nassertr, x, and y.

Referenced by PaletteImage::ClearedRegion::ClearedRegion(), PaletteImage::get_page(), place_at(), and PaletteImage::setup_shadow_image().

int TexturePlacement::get_placed_y  )  const
 

Returns the Y pixel at which the texture has been placed within its PaletteImage.

It is an error to call this unless is_placed() returns true.

Definition at line 634 of file texturePlacement.cxx.

References _omit_reason, is_placed(), mark_eggs_stale(), nassertv, and OR_none.

Referenced by PaletteImage::ClearedRegion::ClearedRegion(), place_at(), and PaletteImage::setup_shadow_image().

int TexturePlacement::get_placed_y_size  )  const
 

Returns the size in the Y dimension, in pixels, of the texture image as it has been placed within the palette.

Definition at line 670 of file texturePlacement.cxx.

References TexturePosition::_margin, TexturePosition::_max_uv, TexturePosition::_min_uv, _placed, TexturePosition::_x, TexturePosition::_y, is_placed(), nassertv, and TexCoordd.

Referenced by PaletteImage::ClearedRegion::ClearedRegion(), PaletteImage::get_page(), place_at(), and PaletteImage::setup_shadow_image().

const TextureProperties & TexturePlacement::get_properties  )  const
 

Returns the grouping properties of the image.

Definition at line 149 of file texturePlacement.cxx.

References _references, and TextureReference::mark_egg_stale().

TextureImage * TexturePlacement::get_texture void   )  const
 

Returns the texture that this placement represents.

Definition at line 136 of file texturePlacement.cxx.

References _group.

Referenced by DestTextureImage::DestTextureImage(), PaletteGroup::is_preferred_over(), and place_at().

virtual TypeHandle TexturePlacement::get_type void   )  const [inline, virtual]
 

Reimplemented from TypedWritable.

Definition at line 154 of file texturePlacement.h.

References SortPlacementBySize::operator()().

double TexturePlacement::get_uv_area  )  const
 

Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.

1.0 is the entire texture; values greater than 1 imply the texture repeats.

Definition at line 543 of file texturePlacement.cxx.

References _placed, TexturePosition::_y_size, is_placed(), and nassertr.

Referenced by PaletteGroup::get_page().

int TexturePlacement::get_x_size  )  const
 

Returns the size in the X dimension, in pixels, of the texture image as it must appear in the palette.

This accounts for any growing or shrinking of the texture due to the UV coordinate range.

Definition at line 503 of file texturePlacement.cxx.

References _placed, TexturePosition::_x, is_placed(), and nassertr.

Referenced by PaletteGroup::get_page().

int TexturePlacement::get_y_size  )  const
 

Returns the size in the Y dimension, in pixels, of the texture image as it must appear in the palette.

This accounts for any growing or shrinking of the texture due to the UV coordinate range.

Definition at line 523 of file texturePlacement.cxx.

References _placed, TexturePosition::_y, is_placed(), and nassertr.

Referenced by PaletteGroup::get_page().

void TexturePlacement::init_type void   )  [inline, static]
 

Reimplemented from TypedWritable.

Definition at line 149 of file texturePlacement.h.

References _type_handle.

bool TexturePlacement::intersects int  x,
int  y,
int  x_size,
int  y_size
 

Returns true if the particular position this texture has been assigned to overlaps the rectangle whose top left corner is at x, y and whose size is given by x_size, y_size, or false otherwise.

Definition at line 808 of file texturePlacement.cxx.

bool TexturePlacement::is_filled  )  const
 

Returns true if the texture has been filled (i.e.

fill_image() has been called) since it was placed.

Definition at line 917 of file texturePlacement.cxx.

References _position.

bool TexturePlacement::is_placed  )  const
 

Returns true if the texture has been placed on a palette image, false otherwise.

This will generally be true if get_omit_reason() returns OR_none or OR_solitary and false otherwise.

Definition at line 567 of file texturePlacement.cxx.

Referenced by PaletteGroup::get_dependency_order(), get_omit_reason(), get_placed_x(), get_placed_x_size(), get_placed_y(), get_placed_y_size(), get_uv_area(), get_x_size(), get_y_size(), omit_solitary(), PalettePage::place(), and place_at().

bool TexturePlacement::is_size_known  )  const
 

Returns true if the texture's size is known, false otherwise.

Usually this can only be false after determine_size() has been called there is something wrong with the texture (in which case the placement will automatically omit itself from the palette anyway).

Definition at line 469 of file texturePlacement.cxx.

References _image, and NULL.

Referenced by PaletteGroup::is_preferred_over().

TypedWritable * TexturePlacement::make_TexturePlacement const FactoryParams params  )  [static, protected]
 

This method is called by the BamReader when an object of this type is encountered in a Bam file; it should allocate and return a new object with all the data read.

Definition at line 1232 of file texturePlacement.cxx.

Referenced by mark_unfilled().

void TexturePlacement::mark_eggs_stale  ) 
 

Marks all the egg files that reference this placement stale.

Presumably this is called after moving the texture around in the palette or something.

Definition at line 222 of file texturePlacement.cxx.

References _omit_reason, _texture, force_replace(), ImageFile::is_size_known(), and OR_unknown.

Referenced by get_page(), get_placed_x(), and get_placed_y().

void TexturePlacement::mark_unfilled  ) 
 

Marks the texture as unfilled, so that it will need to be copied into the palette image again.

Definition at line 932 of file texturePlacement.cxx.

References get_class_type(), BamReader::get_factory(), and make_TexturePlacement().

void TexturePlacement::not_solitary  ) 
 

Indicates that the texture, formerly indicated as solitary, is now no longer.

Definition at line 785 of file texturePlacement.cxx.

References _image, _texture, and TexCoordd.

void TexturePlacement::omit_solitary  ) 
 

Sets the omit reason (returned by get_omit()) to OR_solitary, indicating that the palettized version of the texture should not be used because it is the only texture on a PaletteImage.

However, the texture is still considered placed, and is_placed() will return true.

Definition at line 766 of file texturePlacement.cxx.

References _is_filled, compute_tex_matrix(), is_placed(), nassertv, and TexCoordd.

void TexturePlacement::place_at PaletteImage image,
int  x,
int  y
 

Assigns the texture to a particular position within the indicated PaletteImage.

It is an error to call this if the texture has already been placed elsewhere.

Definition at line 709 of file texturePlacement.cxx.

References _placed, TexturePosition::_wrap_u, TexturePosition::_wrap_v, Namable::get_name(), get_placed_uv_area(), get_placed_x(), get_placed_x_size(), get_placed_y(), get_placed_y_size(), get_texture(), indent(), is_placed(), and EggTexture::WM_unspecified.

void TexturePlacement::register_with_read_factory void   )  [static]
 

Registers the current object as something that can be read from a Bam file.

Definition at line 1125 of file texturePlacement.cxx.

void TexturePlacement::remove_egg TextureReference reference  ) 
 

Notes that a particular egg file is no longer using this particular TexturePlacement.

Definition at line 200 of file texturePlacement.cxx.

References _dest.

Referenced by TextureReference::get_max_uv().

void TexturePlacement::set_dest DestTextureImage dest  ) 
 

Sets the DestTextureImage that corresponds to this texture as it was copied to the install directory.

Definition at line 242 of file texturePlacement.cxx.

References _has_uvs, _position, TexCoordd, and EggTexture::WM_clamp.

Referenced by TextureImage::get_preferred_source().

void TexturePlacement::write_datagram BamWriter writer,
Datagram datagram
[virtual]
 

Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.

Reimplemented from TypedWritable.

Definition at line 1143 of file texturePlacement.cxx.

void TexturePlacement::write_placed ostream &  out,
int  indent_level = 0
 

Writes the placement position information on a line by itself.

Definition at line 879 of file texturePlacement.cxx.


Member Data Documentation

DestTextureImage* TexturePlacement::_dest [private]
 

Definition at line 116 of file texturePlacement.h.

Referenced by remove_egg().

PaletteGroup* TexturePlacement::_group [private]
 

Definition at line 114 of file texturePlacement.h.

Referenced by get_texture(), and ~TexturePlacement().

bool TexturePlacement::_has_uvs [private]
 

Definition at line 118 of file texturePlacement.h.

Referenced by set_dest().

PaletteImage* TexturePlacement::_image [private]
 

Definition at line 115 of file texturePlacement.h.

Referenced by get_image(), get_omit_reason(), get_page(), get_placed_uv_area(), is_size_known(), and not_solitary().

bool TexturePlacement::_is_filled [private]
 

Definition at line 122 of file texturePlacement.h.

Referenced by flag_error_image(), get_image(), omit_solitary(), and TexturePlacement().

int TexturePlacement::_num_references [private]
 

Definition at line 143 of file texturePlacement.h.

Referenced by flag_error_image().

OmitReason TexturePlacement::_omit_reason [private]
 

Definition at line 124 of file texturePlacement.h.

Referenced by flag_error_image(), get_image(), get_page(), get_placed_x(), get_placed_y(), mark_eggs_stale(), and TexturePlacement().

TexturePosition TexturePlacement::_placed [private]
 

Definition at line 123 of file texturePlacement.h.

Referenced by fill_image(), flag_error_image(), get_image(), get_placed_uv_area(), get_placed_x_size(), get_placed_y_size(), get_uv_area(), get_x_size(), get_y_size(), and place_at().

TexturePosition TexturePlacement::_position [private]
 

Definition at line 120 of file texturePlacement.h.

Referenced by fill_image(), get_image(), is_filled(), and set_dest().

References TexturePlacement::_references [private]
 

Definition at line 127 of file texturePlacement.h.

Referenced by add_egg(), fill_image(), get_dest(), get_group(), and get_properties().

bool TexturePlacement::_size_known [private]
 

Definition at line 119 of file texturePlacement.h.

TextureImage* TexturePlacement::_texture [private]
 

Definition at line 113 of file texturePlacement.h.

Referenced by get_name(), mark_eggs_stale(), and not_solitary().

TypeHandle TexturePlacement::_type_handle [static, private]
 

Reimplemented from TypedWritable.

Definition at line 38 of file texturePlacement.cxx.

Referenced by init_type().


The documentation for this class was generated from the following files:
Generated on Fri May 2 03:28:06 2003 for Panda-Tool by doxygen1.3