source: trunk/packages/vizservers/nanovis/Plane.cpp @ 3596

Last change on this file since 3596 was 3502, checked in by ldelgass, 12 years ago

Add basic VTK structured points reader to nanovis, update copyright dates.

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * Plane.cpp: plane class
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16#include <assert.h>
17
18#include "Plane.h"
19
20using namespace nv;
21
22Plane::Plane(float _a, float _b, float _c, float _d) :
23    a(_a),
24    b(_b),
25    c(_c),
26    d(_d)
27{
28    assert(a != 0 || b != 0 || c != 0);
29}
30
31Plane::Plane(float coeffs[4])
32{
33    a = coeffs[0];
34    b = coeffs[1];
35    c = coeffs[2];
36    d = coeffs[3];
37
38    assert(a != 0 || b != 0 || c != 0);
39}
40
41void
42Plane::transform(const vrmath::Matrix4x4d& mat)
43{
44    vrmath::Vector4f coeffs(a, b, c, d);
45
46    vrmath::Matrix4x4d inv = mat.inverse();
47    vrmath::Vector4f new_coeffs = inv.preMultiplyRowVector(coeffs);
48    a = new_coeffs.x;
49    b = new_coeffs.y;
50    c = new_coeffs.z;
51    d = new_coeffs.w;
52}
53
54void
55Plane::getPoint(vrmath::Vector3f& point)
56{
57    if (a != 0) {
58        point.x = -d/a;
59        point.y = 0;
60        point.z = 0;
61    } else if (b != 0) {
62        point.y = -d/b;
63        point.x = 0;
64        point.z = 0;
65    } else if (c != 0) {
66        point.z = -d /c;
67        point.y = 0;
68        point.x = 0;
69    } else {
70        assert(false);
71    }
72}
Note: See TracBrowser for help on using the repository browser.