Line data Source code
1 :
2 : /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2011, Daniel Nachbaur <danielnachbaur@gmail.com>
4 : *
5 : * This library is free software; you can redistribute it and/or modify it under
6 : * the terms of the GNU Lesser General Public License version 2.1 as published
7 : * by the Free Software Foundation.
8 : *
9 : * This library is distributed in the hope that it will be useful, but WITHOUT
10 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 : * details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public License
15 : * along with this library; if not, write to the Free Software Foundation, Inc.,
16 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 : */
18 :
19 : #include "compoundUpdateInputVisitor.h"
20 :
21 : #include "frame.h"
22 : #include "frameData.h"
23 : #include "log.h"
24 : #include "server.h"
25 : #include "tileQueue.h"
26 :
27 : #include <eq/fabric/iAttribute.h>
28 :
29 : namespace eq
30 : {
31 : namespace server
32 : {
33 28 : CompoundUpdateInputVisitor::CompoundUpdateInputVisitor(
34 : const Compound::FrameMap& outputFrames,
35 28 : const Compound::TileQueueMap& outputQueues)
36 : : _outputFrames(outputFrames)
37 28 : , _outputQueues(outputQueues)
38 : {
39 28 : }
40 :
41 72 : VisitorResult CompoundUpdateInputVisitor::visit(Compound* compound)
42 : {
43 72 : if (!compound->isActive())
44 28 : return TRAVERSE_PRUNE;
45 :
46 44 : _updateQueues(compound);
47 44 : _updateFrames(compound);
48 44 : return TRAVERSE_CONTINUE;
49 : }
50 :
51 44 : void CompoundUpdateInputVisitor::_updateQueues(const Compound* compound)
52 : {
53 44 : const TileQueues& inputQueues = compound->getInputTileQueues();
54 44 : for (TileQueuesCIter i = inputQueues.begin(); i != inputQueues.end(); ++i)
55 : {
56 : //----- Find corresponding output queue
57 0 : TileQueue* queue = *i;
58 0 : const std::string& name = queue->getName();
59 :
60 0 : Compound::TileQueueMap::const_iterator j = _outputQueues.find(name);
61 :
62 0 : if (j == _outputQueues.end())
63 : {
64 0 : LBVERB << "Can't find matching output queue, ignoring input queue "
65 0 : << name << std::endl;
66 0 : queue->unsetData();
67 0 : continue;
68 : }
69 :
70 0 : LBASSERT(queue->isAttached());
71 :
72 0 : TileQueue* outputQueue = j->second;
73 0 : queue->setOutputQueue(outputQueue, compound);
74 : }
75 44 : }
76 :
77 44 : void CompoundUpdateInputVisitor::_updateFrames(Compound* compound)
78 : {
79 44 : const Channel* channel = compound->getChannel();
80 44 : if (!compound->testInheritTask(fabric::TASK_ASSEMBLE) || !channel)
81 28 : return;
82 :
83 16 : const Frames& inputFrames = compound->getInputFrames();
84 16 : if (inputFrames.empty())
85 : {
86 12 : compound->unsetInheritTask(fabric::TASK_ASSEMBLE);
87 12 : return;
88 : }
89 :
90 8 : for (FramesCIter i = inputFrames.begin(); i != inputFrames.end(); ++i)
91 : {
92 : //----- Find corresponding output frame
93 4 : Frame* frame = *i;
94 4 : const std::string& name = frame->getName();
95 :
96 4 : Compound::FrameMap::const_iterator j = _outputFrames.find(name);
97 :
98 4 : if (j == _outputFrames.end())
99 : {
100 0 : LBVERB << "Can't find matching output frame, ignoring input frame "
101 0 : << name << std::endl;
102 0 : frame->unsetData();
103 0 : continue;
104 : }
105 :
106 : //----- Set frame parameters:
107 : // 1) Frame offset
108 4 : Frame* outputFrame = j->second;
109 4 : const Channel* iChannel = compound->getInheritChannel();
110 4 : Vector2i frameOffset = outputFrame->getMasterData()->getOffset() +
111 8 : frame->getNativeOffset();
112 :
113 4 : if (outputFrame->getCompound()->getInheritChannel() != iChannel)
114 0 : frameOffset = frame->getNativeOffset();
115 4 : else if (channel != iChannel)
116 : {
117 : // compute delta offset between source and destination, since the
118 : // channel's native origin (as opposed to destination) is used.
119 0 : const Viewport& frameVP = frame->getViewport();
120 : const PixelViewport& inheritPVP =
121 0 : compound->getInheritPixelViewport();
122 0 : PixelViewport framePVP(inheritPVP);
123 :
124 0 : framePVP.apply(frameVP);
125 0 : frameOffset.x() -= framePVP.x;
126 0 : frameOffset.y() -= framePVP.y;
127 :
128 0 : const PixelViewport& iChannelPVP = iChannel->getPixelViewport();
129 0 : frameOffset.x() -= iChannelPVP.x;
130 0 : frameOffset.y() -= iChannelPVP.y;
131 : }
132 4 : frame->setOffset(frameOffset);
133 :
134 : // 2) zoom
135 4 : _updateZoom(compound, frame, outputFrame);
136 :
137 : // 3) TODO input frames are moved using the offset. The pvp signifies
138 : // the pixels to be used from the frame data.
139 : // framePVP.x = static_cast< int32_t >( frameVP.x * inheritPVP.w );
140 : // framePVP.y = static_cast< int32_t >( frameVP.y * inheritPVP.h );
141 : // frame->setInheritPixelViewport( framePVP );
142 : //----- Link input frame to output frame (connects frame data)
143 4 : outputFrame->addInputFrame(frame, compound);
144 :
145 4 : for (unsigned k = 0; k < NUM_EYES; ++k)
146 : {
147 4 : const Eye eye = Eye(1 << k);
148 8 : if (compound->isInheritActive(eye) && // eye pass used
149 4 : outputFrame->hasData(eye)) // output data for eye pass
150 : {
151 4 : frame->commit();
152 4 : LBLOG(LOG_ASSEMBLY)
153 : << "Input frame \"" << name << "\" on channel \""
154 0 : << channel->getName() << "\" id " << frame->getID() << " v"
155 4 : << frame->getVersion() << "\" tile pos "
156 0 : << frame->getOffset() << ' ' << frame->getZoom()
157 12 : << std::endl;
158 4 : break;
159 : }
160 : }
161 : }
162 : }
163 :
164 4 : void CompoundUpdateInputVisitor::_updateZoom(const Compound* compound,
165 : Frame* frame,
166 : const Frame* outputFrame)
167 : {
168 4 : Zoom zoom = frame->getNativeZoom();
169 4 : if (!zoom.isValid()) // if zoom is not set, inherit from parent
170 4 : zoom = compound->getInheritZoom();
171 :
172 : // Zoom difference between output and input
173 4 : const FrameData* frameData = outputFrame->getMasterData();
174 4 : zoom /= frameData->getZoom();
175 :
176 4 : frame->setZoom(zoom);
177 4 : }
178 : }
179 60 : }
|