File: Instance.cpp

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (72 lines) | stat: -rw-r--r-- 2,075 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
66
67
68
69
70
71
72
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

// ospray
#include "Instance.h"

namespace ospray {

Instance::Instance(api::ISPCDevice &device, Group *_group)
    : AddStructShared(device.getDRTDevice(), device), groupAPI(_group)
{
  managedObjectType = OSP_INSTANCE;
}

std::string Instance::toString() const
{
  return "ospray::Instance";
}

void Instance::commit()
{
  group = getParamObject<Group>("group", groupAPI.ptr);
  if (!group)
    throw std::runtime_error(toString() + " received NULL 'group'");

  motionTransform.readParams(*this);

  // Initialize shared structure
  getSh()->group = group->getSh();
  getSh()->xfm = motionTransform.transform;
  getSh()->rcp_xfm = rcp(getSh()->xfm);
  getSh()->motionBlur = motionTransform.motionBlur;
  getSh()->userID = getParam<uint32>("id", RTC_INVALID_GEOMETRY_ID);
}

box3f Instance::getBounds() const
{
  box3f bounds;
  const box3f groupBounds = group->getBounds();
  // TODO get better bounds:
  // - uses bounds at time 0.5, wrong if different shutter is used and does not
  //   include motion at all
  // alternatives:
  // - merge linear bounds from Embree (which is for time [0, 1]), but this
  //   needs a temporary RTCScene just for this instance
  // - extend over all transformed bounds
  //   - this is too big, because keys outside of time [0, 1] are included
  //   - yet is is also too small, because interpolated transformations can
  //     lead to leaving the bounds of keys
  bounds.extend(xfmBounds(motionTransform.transform, groupBounds));
  return bounds;
}

void Instance::setEmbreeGeom(RTCScene scene, unsigned int geomID)
{
  RTCGeometry geom = rtcGetGeometry(scene, geomID);
  motionTransform.setEmbreeTransform(geom);
  getSh()->scene = scene;
  getSh()->geomID = geomID;
  if (getSh()->motionBlur) {
    rtcGetGeometryTransformFromScene(scene,
        geomID,
        .5f,
        RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR,
        &getSh()->xfm); // for SciVis
    getSh()->rcp_xfm = rcp(getSh()->xfm);
  }
}

OSPTYPEFOR_DEFINITION(Instance *);

} // namespace ospray