Panda3D

texturePlacement.h

00001 // Filename: texturePlacement.h
00002 // Created by:  drose (28Nov00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef TEXTUREPLACEMENT_H
00016 #define TEXTUREPLACEMENT_H
00017 
00018 #include "pandatoolbase.h"
00019 
00020 #include "omitReason.h"
00021 #include "texturePosition.h"
00022 
00023 #include "typedWritable.h"
00024 #include "luse.h"
00025 
00026 #include "pset.h"
00027 
00028 class TextureImage;
00029 class DestTextureImage;
00030 class PaletteGroup;
00031 class PaletteImage;
00032 class PalettePage;
00033 class TextureProperties;
00034 class TextureReference;
00035 class PNMImage;
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : TexturePlacement
00039 // Description : This corresponds to a particular assignment of a
00040 //               TextureImage with a PaletteGroup, and specifically
00041 //               describes which PaletteImage (if any), and where on
00042 //               the PaletteImage, the TextureImage has been assigned
00043 //               to.
00044 ////////////////////////////////////////////////////////////////////
00045 class TexturePlacement : public TypedWritable {
00046 private:
00047   TexturePlacement();
00048 
00049 public:
00050   TexturePlacement(TextureImage *texture, PaletteGroup *group);
00051   ~TexturePlacement();
00052 
00053   const string &get_name() const;
00054   TextureImage *get_texture() const;
00055   const TextureProperties &get_properties() const;
00056   PaletteGroup *get_group() const;
00057 
00058   void add_egg(TextureReference *reference);
00059   void remove_egg(TextureReference *reference);
00060   void mark_eggs_stale();
00061 
00062   void set_dest(DestTextureImage *dest);
00063   DestTextureImage *get_dest() const;
00064 
00065   bool determine_size();
00066   bool is_size_known() const;
00067   OmitReason get_omit_reason() const;
00068   int get_x_size() const;
00069   int get_y_size() const;
00070   double get_uv_area() const;
00071 
00072   bool is_placed() const;
00073   PaletteImage *get_image() const;
00074   PalettePage *get_page() const;
00075   int get_placed_x() const;
00076   int get_placed_y() const;
00077   int get_placed_x_size() const;
00078   int get_placed_y_size() const;
00079   double get_placed_uv_area() const;
00080 
00081   void place_at(PaletteImage *image, int x, int y);
00082   void force_replace();
00083   void omit_solitary();
00084   void not_solitary();
00085   bool intersects(int x, int y, int x_size, int y_size);
00086 
00087   void compute_tex_matrix(LMatrix3d &transform);
00088 
00089   void write_placed(ostream &out, int indent_level = 0);
00090 
00091   bool is_filled() const;
00092   void mark_unfilled();
00093   void fill_image(PNMImage &image);
00094   void fill_swapped_image(PNMImage &image, int index);
00095   void flag_error_image(PNMImage &image);
00096 
00097   typedef pvector<TextureImage *> TextureSwaps;
00098   TextureSwaps _textureSwaps;
00099 
00100 private:
00101   void compute_size_from_uvs(const LTexCoordd &min_uv, const LTexCoordd &max_uv);
00102 
00103   TextureImage *_texture;
00104   PaletteGroup *_group;
00105   PaletteImage *_image;
00106   DestTextureImage *_dest;
00107 
00108   bool _has_uvs;
00109   bool _size_known;
00110   TexturePosition _position;
00111 
00112   bool _is_filled;
00113   TexturePosition _placed;
00114   OmitReason _omit_reason;
00115 
00116   typedef pset<TextureReference *> References;
00117   References _references;
00118 
00119   // The TypedWritable interface follows.
00120 public:
00121   static void register_with_read_factory();
00122   virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00123   virtual int complete_pointers(TypedWritable **p_list,
00124                                 BamReader *manager);
00125 
00126 protected:
00127   static TypedWritable *make_TexturePlacement(const FactoryParams &params);
00128   void fillin(DatagramIterator &scan, BamReader *manager);
00129 
00130 private:
00131   // This value is only filled in while reading from the bam file;
00132   // don't use it otherwise.
00133   int _num_references;
00134   int _margin_override;
00135   int _num_textureSwaps;
00136 
00137 public:
00138   static TypeHandle get_class_type() {
00139     return _type_handle;
00140   }
00141   static void init_type() {
00142     TypedWritable::init_type();
00143     register_type(_type_handle, "TexturePlacement",
00144                   TypedWritable::get_class_type());
00145   }
00146   virtual TypeHandle get_type() const {
00147     return get_class_type();
00148   }
00149 
00150 private:
00151   static TypeHandle _type_handle;
00152 };
00153 
00154 
00155 // This is an STL object to sort an array of TexturePlacement pointers
00156 // in order from biggest to smallest.
00157 class SortPlacementBySize {
00158 public:
00159   bool operator ()(TexturePlacement *a, TexturePlacement *b) const;
00160 };
00161 
00162 #endif
00163 
 All Classes Functions Variables Enumerations