cvs: pear /Image_3D/Image/3D/Paintable Object.php /Image_3D/Image/3D/Paintable/Object Quadcube.php /Image_3D/docs/examples quadcube.php
| From: | Kore Nordmann | Date: | Tue, 21 Mar 2006 22:49:00 +0000 |
| Subject: | cvs: pear /Image_3D/Image/3D/Paintable Object.php /Image_3D/Image/3D/Paintable/Object Quadcube.php /Image_3D/docs/examples quadcube.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-39227@lists.php.net to get a copy of this message | ||
kore Tue Mar 21 22:49:00 2006 UTC
Added files:
/pear/Image_3D/docs/examples quadcube.php
/pear/Image_3D/Image/3D/Paintable/Object Quadcube.php
Modified files:
/pear/Image_3D/Image/3D/Paintable Object.php
Log:
- Added method to Image_3D_Object to return a node-edge inzidenz graph from
array of polygones
- Added quadcube to test subdivision surfaces
http://cvs.php.net/viewcvs.cgi/pear/Image_3D/Image/3D/Paintable/Object.php?r1=1.5&r2=1.6&diff_format=u
Index: pear/Image_3D/Image/3D/Paintable/Object.php
diff -u pear/Image_3D/Image/3D/Paintable/Object.php:1.5
pear/Image_3D/Image/3D/Paintable/Object.php:1.6
--- pear/Image_3D/Image/3D/Paintable/Object.php:1.5 Fri Dec 2 16:01:30 2005
+++ pear/Image_3D/Image/3D/Paintable/Object.php Tue Mar 21 22:49:00 2006
@@ -27,7 +27,7 @@
* @author Kore Nordmann <3d@kore-nordmann.de>
* @copyright 1997-2005 Kore Nordmann
* @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1
- * @version CVS: $Id: Object.php,v 1.5 2005/12/02 16:01:30 kore Exp $
+ * @version CVS: $Id: Object.php,v 1.6 2006/03/21 22:49:00 kore Exp $
* @link http://pear.php.net/package/PackageName
* @since File available since Release 0.1.0
*/
@@ -80,6 +80,72 @@
protected function _addPolygon(Image_3D_Polygon $polygon) {
$this->_polygones[] = $polygon;
}
+
+ public function buildInzidenzGraph() {
+ $polygons = $this->getPolygones();
+
+ $surfaces = array();
+ $edges = array();
+ $points = array();
+
+ $point_hash = array();
+ $edge_hash = array();
+
+ foreach ($polygons as $nr => $polygon) {
+ $p_points = $polygon->getPoints();
+
+ $last_index = false;
+ $first_index = false;
+ foreach ($p_points as $point) {
+ // Add point to edge
+ $p_p_hash = $point->__toString();
+ if (isset($point_hash[$p_p_hash])) {
+ $p_p_index = $point_hash[$p_p_hash];
+ } else {
+ $points[] = $point;
+ $p_p_index = count($points) - 1;
+ $point_hash[$p_p_hash] = $p_p_index;
+ }
+
+ // Add edge to surface
+ if ($last_index !== false) {
+ $e_points = array($p_p_index, $last_index);
+ sort($e_points);
+ $p_e_hash = implode(' -> ', $e_points);
+ if (isset($edge_hash[$p_e_hash])) {
+ $surfaces[$nr][] = $edge_hash[$p_e_hash];
+ } else {
+ $edges[] = $e_points;
+ $edge_hash[$p_e_hash] = count($edges) - 1;
+ $surfaces[$nr][] = $edge_hash[$p_e_hash];
+ }
+ } else {
+ $first_index = $p_p_index;
+ }
+
+ // Prepare last index for next iteration
+ $last_index = $p_p_index;
+ }
+
+ // Close surface
+ $e_points = array($first_index, $last_index);
+ sort($e_points);
+ $p_e_hash = implode(' -> ', $e_points);
+ if (isset($edge_hash[$p_e_hash])) {
+ $surfaces[$nr][] = $edge_hash[$p_e_hash];
+ } else {
+ $edges[] = $e_points;
+ $edge_hash[$p_e_hash] = count($edges) - 1;
+ $surfaces[$nr][] = $edge_hash[$p_e_hash];
+ }
+ }
+
+ return array(
+ 'surfaces' => $surfaces,
+ 'edges' => $edges,
+ 'points' => $points,
+ );
+ }
}
-?>
\ No newline at end of file
+?>
http://cvs.php.net/viewcvs.cgi/pear/Image_3D/docs/examples/quadcube.php?view=markup&rev=1.1
Index: pear/Image_3D/docs/examples/quadcube.php
+++ pear/Image_3D/docs/examples/quadcube.php
<?php
set_time_limit(0);
require_once('Image/3D.php');
$world = new Image_3D();
$world->setColor(new Image_3D_Color(240, 240, 240));
$light = $world->createLight('Light', array(0, 0, -500));
$light->setColor(new Image_3D_Color(255, 255, 255));
$cube = $world->createObject('quadcube', array(150, 150, 150));
$cube->setColor(new Image_3D_Color(50, 50, 250, 150));
$cube->buildInzidenzGraph();
$world->transform($world->createMatrix('Rotation', array(15, 15, 0)));
$world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, true);
$world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true);
$world->createRenderer('perspectively');
$world->createDriver('GD');
$world->render(400, 400, 'Image_3D_Quadcube.png');
echo $world->stats();
http://cvs.php.net/viewcvs.cgi/pear/Image_3D/Image/3D/Paintable/Object/Quadcube.php?view=markup&rev=1.1
Index: pear/Image_3D/Image/3D/Paintable/Object/Quadcube.php
+++ pear/Image_3D/Image/3D/Paintable/Object/Quadcube.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* 3d Library
*
* PHP versions 5
*
* LICENSE:
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category Image
* @package Image_3D
* @author Kore Nordmann <3d@kore-nordmann.de>
* @copyright 1997-2005 Kore Nordmann
* @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1
* @version CVS: $Id: Quadcube.php,v 1.1 2006/03/21 22:49:00 kore Exp $
* @link http://pear.php.net/package/PackageName
* @since File available since Release 0.1.0
*/
require_once('Image/3D/Paintable/Object.php');
/**
* Image_3D_Object_Cube
*
*
*
* @category Image
* @package Image_3D
* @author Kore Nordmann <3d@kore-nordmann.de>
* @copyright 1997-2005 Kore Nordmann
* @license http://www.gnu.org/licenses/lgpl.txt lgpl 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/PackageName
* @since Class available since Release 0.1.0
*/
class Image_3D_Object_Quadcube extends Image_3D_Object {
protected $_points;
public function __construct($parameter) {
parent::__construct();
$x = (float) @$parameter[0];
$y = (float) @$parameter[1];
$z = (float) @$parameter[2];
$this->_points = array();
$this->_points[1] = new Image_3D_Point(-$x / 2, -$y / 2, -$z / 2);
$this->_points[2] = new Image_3D_Point(-$x / 2, -$y / 2, $z / 2);
$this->_points[3] = new Image_3D_Point(-$x / 2, $y / 2, -$z / 2);
$this->_points[4] = new Image_3D_Point(-$x / 2, $y / 2, $z / 2);
$this->_points[5] = new Image_3D_Point( $x / 2, -$y / 2, -$z / 2);
$this->_points[6] = new Image_3D_Point( $x / 2, -$y / 2, $z / 2);
$this->_points[7] = new Image_3D_Point( $x / 2, $y / 2, -$z / 2);
$this->_points[8] = new Image_3D_Point( $x / 2, $y / 2, $z / 2);
// Oben & Unten
$this->_addPolygon(new Image_3D_Polygon($this->_points[3], $this->_points[4],
$this->_points[8], $this->_points[7]));
$this->_addPolygon(new Image_3D_Polygon($this->_points[2], $this->_points[1],
$this->_points[5], $this->_points[6]));
// Links & Rechts
$this->_addPolygon(new Image_3D_Polygon($this->_points[3], $this->_points[1],
$this->_points[2], $this->_points[4]));
$this->_addPolygon(new Image_3D_Polygon($this->_points[8], $this->_points[6],
$this->_points[5], $this->_points[7]));
// Rueck- & Frontseite
$this->_addPolygon(new Image_3D_Polygon($this->_points[2], $this->_points[6],
$this->_points[8], $this->_points[4]));
$this->_addPolygon(new Image_3D_Polygon($this->_points[1], $this->_points[3],
$this->_points[7], $this->_points[5]));
}
}