ClipAttributes.code 8.98 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2 3 4 5 6 7 8 9 10 11 12 13
Function: CopyAttributes
Declaration: virtual bool CopyAttributes(const AttributeGroup *);
Definition:
// ****************************************************************************
// Method: ClipAttributes::CopyAttributes
//
// Purpose: 
//   CopyAttributes method for the ClipAttributes class.
//
// Programmer: Brad Whitlock
// Creation:   Tue Oct 29 08:57:18 PDT 2002
//
// Modifications:
14 15
//   Gunther H. Weber, Tue Aug 14 12:50:19 PDT 2007
//   Plane tool can modify clip planes 
hrchilds's avatar
hrchilds committed
16
//
17 18 19
//   Jeremy Meredith, Thu Aug  7 15:34:07 EDT 2008
//   Add missing case in switch to avoid warnings.
//
hrchilds's avatar
hrchilds committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33
// ****************************************************************************

bool
ClipAttributes::CopyAttributes(const AttributeGroup *atts)
{
    bool retval = false;

    if(TypeName() == atts->TypeName())
    {
        // Call assignment operator.
        const ClipAttributes *tmp = (const ClipAttributes *)atts;
        *this = *tmp;
        retval = true;
    }
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    else if(atts->TypeName() == "PlaneAttributes")
    {
        if(GetFuncType() == Plane && GetPlaneToolControlledClipPlane() != None)
        {
            const PlaneAttributes *tmp = (const PlaneAttributes *)atts;

            switch (GetPlaneToolControlledClipPlane())
            {
                case Plane1:
                    if(GetPlane1Status())
                    {
                        SetPlane1Origin(tmp->GetOrigin());
                        SetPlane1Normal(tmp->GetNormal());
                        retval = true;
                    }
                    break;
                case Plane2:
                    if(GetPlane2Status())
                    {
                        SetPlane2Origin(tmp->GetOrigin());
                        SetPlane2Normal(tmp->GetNormal());
                        retval = true;
                    }
                    break;
                case Plane3:
                    if(GetPlane3Status())
                    {
                        SetPlane3Origin(tmp->GetOrigin());
                        SetPlane3Normal(tmp->GetNormal());
                        retval = true;
                    }
                    break;
66 67
                case None:
                    break;
68 69 70
            }
        }
    }
hrchilds's avatar
hrchilds committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    else if(atts->TypeName() == "BoxExtents")
    {
        if(GetFuncType() == Plane)
        {
            const BoxExtents *tmp = (const BoxExtents *)atts;
            const double *extents = tmp->GetExtents();
            double origin[] = {extents[0], extents[2], extents[4]};
            double xnorm[] = {1., 0., 0.};
            double ynorm[] = {0., 1., 0.};
            double znorm[] = {0., 0., 1.};
            if(GetPlane1Status())
            {
                SetPlane1Origin(origin);
                SetPlane1Normal(xnorm);
            }
            if(GetPlane2Status())
            {
                SetPlane2Origin(origin);
                SetPlane2Normal(ynorm);
            }
            if(GetPlane3Status())
            {
                SetPlane3Origin(origin);
                SetPlane3Normal(znorm);
            }

            retval = true;
        }
    }
    else if(atts->TypeName() == "SphereAttributes")
    {
        if(GetFuncType() == Sphere)
        {
            const SphereAttributes *sphere = (const SphereAttributes *)atts;
            SetCenter(sphere->GetOrigin());
            SetRadius(sphere->GetRadius());

            retval = true;
        }
    }

    return retval;
}

Function: CreateCompatible
Declaration: virtual AttributeSubject *CreateCompatible(const std::string &) const;
Definition:
// ****************************************************************************
// Method: ClipAttributes::CreateCompatible
//
// Purpose: 
//   Creates an object of the specified type initialized with the attributes
//   from this object.
//
// Arguments:
//   tname : The typename of the object that we want to create.
//
// Returns:    A new object of the type specified by tname or 0.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Tue Oct 29 08:57:46 PDT 2002
//
// Modifications:
136 137
//   Gunther H. Weber, Tue Aug 14 12:50:19 PDT 2007
//   Plane tool can modify clip planes 
hrchilds's avatar
hrchilds committed
138
//   
139 140 141
//   Jeremy Meredith, Thu Aug  7 15:34:07 EDT 2008
//   Add missing case in switch to avoid warnings.
//
hrchilds's avatar
hrchilds committed
142 143 144 145 146 147 148 149 150 151 152
// ****************************************************************************

AttributeSubject *
ClipAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;

    if(TypeName() == tname)
    {
        retval = new ClipAttributes(*this);
    }
153 154 155
    else if(tname == "PlaneAttributes" && GetPlaneToolControlledClipPlane() != None)
    {
        PlaneAttributes *p = new PlaneAttributes;
bonnell's avatar
bonnell committed
156
        const double *normal_arr = NULL;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

        switch (GetPlaneToolControlledClipPlane())
        {
            case Plane1:
                p->SetOrigin(GetPlane1Origin());
                normal_arr = GetPlane1Normal();
                p->SetNormal(normal_arr);
                break;
            case Plane2:
                p->SetOrigin(GetPlane2Origin());
                normal_arr = GetPlane2Normal();
                p->SetNormal(normal_arr);
                break;
            case Plane3:
                p->SetOrigin(GetPlane3Origin());
                normal_arr = GetPlane3Normal();
                p->SetNormal(normal_arr);
                break;
175 176
            case None:
                break;
177 178 179
        }

        // Compute up vector
180 181 182 183 184 185 186
        double temp[3] = {0, 0, 1};
        if (normal_arr[0] == 0 && normal_arr[1] == 0)
            temp[1] = 1;
        double up[3];
        up[0] = normal_arr[1]*temp[2] - normal_arr[2]*temp[1];
        up[1] = normal_arr[2]*temp[0] - normal_arr[0]*temp[2];
        up[2] = normal_arr[0]*temp[1] - normal_arr[1]*temp[0];
187

188
        p->SetUpAxis(up);
189 190 191 192
        p->SetThreeSpace(true);

        retval = p;
    }
hrchilds's avatar
hrchilds committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    else if(tname == "BoxExtents")
    {
        BoxExtents *b = new BoxExtents;
        double extents[6];
        extents[0] = plane1Origin[0];
        extents[1] = plane1Origin[0]+2.;
        extents[2] = plane1Origin[1];
        extents[3] = plane1Origin[1]+2.;
        extents[4] = plane1Origin[2];
        extents[5] = plane1Origin[2]+2.;
        b->SetExtents(extents);

        retval = b;
    }
    else if(tname == "SphereAttributes")
    {
        SphereAttributes *s = new SphereAttributes;
        s->SetOrigin(center);
        s->SetRadius(radius);

        retval = s;
    }

    return retval;
}
218

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
Function: EqualTo
Declaration: virtual bool EqualTo(const AttributeGroup *atts) const;
Definition:
// ****************************************************************************
// Method: ClipAttributes::EqualTo
//
// Purpose:
//     Determines if the clip attributes are equal to another attributes
//     object.
//
// Arguments:
//   atts : An attribute group.
//
// Returns:    True if this object is equal to atts, false otherwise.
//
// Note:
//
// Programmer: Hank Childs
// Creation:   August 28, 2007
//
239 240 241
//   Jeremy Meredith, Thu Aug  7 15:34:07 EDT 2008
//   Add missing case in switch to avoid warnings.
//
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
// ****************************************************************************

bool
ClipAttributes::EqualTo(const AttributeGroup *atts) const
{
    if ((atts->TypeName() != "PlaneAttributes") || 
        GetPlaneToolControlledClipPlane() == None)
        return AttributeSubject::EqualTo(atts);

    const PlaneAttributes *tmp = (const PlaneAttributes *) atts;

    switch (GetPlaneToolControlledClipPlane())
    {
      case Plane1:
        if (GetPlane1Origin()[0] != tmp->GetOrigin()[0])
            return false;
        if (GetPlane1Origin()[1] != tmp->GetOrigin()[1])
            return false;
        if (GetPlane1Origin()[2] != tmp->GetOrigin()[2])
            return false;

        if (GetPlane1Normal()[0] != tmp->GetNormal()[0])
            return false;
        if (GetPlane1Normal()[1] != tmp->GetNormal()[1])
            return false;
        if (GetPlane1Normal()[2] != tmp->GetNormal()[2])
            return false;

        break;

      case Plane2:
        if (GetPlane2Origin()[0] != tmp->GetOrigin()[0])
            return false;
        if (GetPlane2Origin()[1] != tmp->GetOrigin()[1])
            return false;
        if (GetPlane2Origin()[2] != tmp->GetOrigin()[2])
            return false;

        if (GetPlane2Normal()[0] != tmp->GetNormal()[0])
            return false;
        if (GetPlane2Normal()[1] != tmp->GetNormal()[1])
            return false;
        if (GetPlane2Normal()[2] != tmp->GetNormal()[2])
            return false;

        break;

      case Plane3:
        if (GetPlane3Origin()[0] != tmp->GetOrigin()[0])
            return false;
        if (GetPlane3Origin()[1] != tmp->GetOrigin()[1])
            return false;
        if (GetPlane3Origin()[2] != tmp->GetOrigin()[2])
            return false;

        if (GetPlane3Normal()[0] != tmp->GetNormal()[0])
            return false;
        if (GetPlane3Normal()[1] != tmp->GetNormal()[1])
            return false;
        if (GetPlane3Normal()[2] != tmp->GetNormal()[2])
            return false;

        break;

306 307
        case None:
            break;
308 309 310 311 312 313
    }


    return true;
}