Mercurial > s60_experiments
annotate DemoCube/src/DemoCubeAppView.cpp @ 5:f546bb5370c7 default tip
Added a readme and a TODO in the source code.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 12 Feb 2008 19:09:21 -0600 |
parents | 0a2b5a968ce7 |
children |
rev | line source |
---|---|
0 | 1 /*===================================================================== |
2 | |
3 Copyright © 2007 Nokia Corporation. All rights reserved. | |
4 | |
5 ======================================================================*/ | |
6 | |
7 /* | |
8 ============================================================================ | |
9 Name : DemoCubeAppView.cpp | |
10 Author : Nokia Computer Vision Team in NRC Palo Alto | |
11 Copyright : Your copyright notice | |
12 Description : Application view implementation | |
13 ============================================================================ | |
14 */ | |
15 | |
16 // INCLUDE FILES | |
17 #include <coemain.h> | |
18 #include "DemoCubeAppView.h" | |
19 | |
20 #include "DemoCamera.h" | |
21 #include "ncvImage.h" | |
22 #include "ncvCamus.h" | |
23 #include "ncvOpticalFlow.h" | |
24 #include "ncvEgoMovement.h" | |
25 #include "DemoCube.h" | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
26 #include "ImageLoader.h" |
0 | 27 |
28 #define PADDING_WIDTH 40 | |
29 #define PADDING_HEIGHT 30 | |
30 | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
31 _LIT( KPicture, "firefox.png" ); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
32 |
0 | 33 // ============================ MEMBER FUNCTIONS =============================== |
34 | |
35 // ----------------------------------------------------------------------------- | |
36 // CDemoCubeAppView::NewL() | |
37 // Two-phased constructor. | |
38 // ----------------------------------------------------------------------------- | |
39 // | |
40 CDemoCubeAppView* CDemoCubeAppView::NewL(const TRect& aRect, CDemoCubeAppUi* aAppUi) | |
41 { | |
42 CDemoCubeAppView* self = new(ELeave) CDemoCubeAppView(aAppUi); | |
43 CleanupStack::PushL(self); | |
44 self->ConstructL(aRect); | |
45 CleanupStack::Pop(); | |
46 return self; | |
47 } | |
48 | |
49 // ----------------------------------------------------------------------------- | |
50 // CDemoCubeAppView::ConstructL() | |
51 // Symbian 2nd phase constructor can leave. | |
52 // ----------------------------------------------------------------------------- | |
53 // | |
54 void CDemoCubeAppView::ConstructL( const TRect& aRect ) | |
55 { | |
56 Reset(); | |
57 | |
58 if ( CCamera::CamerasAvailable() ) //Yingen added for detecting camera | |
59 {//Yingen added for detecting camera | |
60 iCamera = CDemoCamera::NewL(aRect.Size() - TSize(PADDING_WIDTH, PADDING_HEIGHT), this); | |
61 iCamera->Acquire(); | |
62 | |
63 iCamusImage = CNokiaCVImage::NewL(); | |
64 iCamusImage->CreateL(iBitmapSize, EColor16M); | |
65 }//Yingen added for detecting camera | |
66 iCube = CDemoCube::NewL(aRect); | |
67 iCubePoints = new(ELeave) CArrayFixFlat<TPoint>(5); | |
68 for(TInt i = 0; i < 5; i++) | |
69 { | |
70 TPoint tmp(0, 0); | |
71 iCubePoints->AppendL(tmp); | |
72 } | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
73 |
0 | 74 // Create a window for this application view |
75 CreateWindowL(); | |
76 | |
77 // Set the windows size | |
78 SetRect( aRect ); | |
79 | |
80 // Activate the window, which makes it ready to be drawn | |
81 ActivateL(); | |
82 } | |
83 | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
84 void CDemoCubeAppView::StartImgLoader() |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
85 { |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
86 // was 50,50 |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
87 TSize iSize(493, 305); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
88 TInt color; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
89 TInt gray; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
90 TDisplayMode displayMode = CEikonEnv::Static()->WsSession().GetDefModeMaxNumColors( color, gray ); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
91 |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
92 iPicture = new (ELeave) CFbsBitmap; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
93 if (iPicture) |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
94 iPicture->Create(iSize, displayMode); //EColor16MA |
5
f546bb5370c7
Added a readme and a TODO in the source code.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
95 // TODO: We're hard-coding the 'c' drive here, but the user |
f546bb5370c7
Added a readme and a TODO in the source code.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
96 // could've installed the program to a different drive. Obtain |
f546bb5370c7
Added a readme and a TODO in the source code.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
97 // the drive letter dynamically. |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
98 iLoader = CImageLoader::NewL( 'c' ); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
99 iLoader->LoadImage( KPicture, iPicture ); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
100 } |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
101 |
0 | 102 // ----------------------------------------------------------------------------- |
103 // CDemoCubeAppView::CDemoCubeAppView() | |
104 // C++ default constructor can NOT contain any code, that might leave. | |
105 // ----------------------------------------------------------------------------- | |
106 // | |
107 CDemoCubeAppView::CDemoCubeAppView(CDemoCubeAppUi* aAppUi) : | |
108 iAppUi(aAppUi), | |
109 iCamera(NULL), | |
110 iCamusImage(NULL), | |
111 iBitmapSize(25, 18), | |
112 iCamus(NULL), | |
113 iOpticalFlow(NULL), | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
114 iCube(NULL), |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
115 iLoader(NULL), |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
116 iPicture(NULL) |
0 | 117 { |
118 } | |
119 | |
120 void CDemoCubeAppView::Reset() | |
121 { | |
122 iCubeWidth = 10; | |
123 iMove.iX = 0.0; | |
124 iMove.iY = 0.0; | |
125 iAngle = 0.0; | |
126 } | |
127 // ----------------------------------------------------------------------------- | |
128 // CDemoCubeAppView::~CDemoCubeAppView() | |
129 // Destructor. | |
130 // ----------------------------------------------------------------------------- | |
131 // | |
132 CDemoCubeAppView::~CDemoCubeAppView() | |
133 { | |
134 // No implementation required | |
135 if(iCamera) | |
136 { | |
137 delete iCamera; | |
138 iCamera = NULL; | |
139 } | |
140 if(iCamusImage) | |
141 { | |
142 delete iCamusImage; | |
143 iCamusImage = NULL; | |
144 } | |
145 if(iCamus) | |
146 { | |
147 delete iCamus; | |
148 iCamus = NULL; | |
149 } | |
150 if(iOpticalFlow) | |
151 { | |
152 delete iOpticalFlow; | |
153 iOpticalFlow = NULL; | |
154 } | |
155 if(iCube) | |
156 { | |
157 delete iCube; | |
158 iCube = NULL; | |
159 } | |
160 if(iCubePoints) | |
161 { | |
162 delete iCubePoints; | |
163 iCubePoints = NULL; | |
164 } | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
165 if(iLoader) |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
166 { |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
167 delete iLoader; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
168 iLoader = NULL; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
169 } |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
170 if(iPicture) |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
171 { |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
172 delete iPicture; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
173 iPicture = NULL; |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
174 } |
0 | 175 } |
176 | |
177 // ----------------------------------------------------------------------------- | |
178 // CDemoCubeAppView::Draw() | |
179 // Draws the display. | |
180 // ----------------------------------------------------------------------------- | |
181 // | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
182 void CDemoCubeAppView::Draw(CFbsBitmap& aBitmap, CArrayFixFlat<TPoint>* aCube) |
0 | 183 { |
184 CWindowGc& gc = SystemGc(); | |
185 gc.Activate(Window()); | |
186 gc.Clear(); | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
187 //gc.BitBlt(TPoint(PADDING_WIDTH / 2, PADDING_HEIGHT / 2), &aBitmap); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
188 |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
189 |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
190 //gc.BitBlt(TPoint(PADDING_WIDTH / 2, PADDING_HEIGHT / 2), iPicture); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
191 gc.BitBlt(TPoint( (TInt)iMove.iY.Real(), (TInt)iMove.iX.Real()), iPicture); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
192 //gc.SetPenColor(TRgb(0xff, 0, 0)); |
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
193 //gc.DrawPolyLine(aCube); |
0 | 194 gc.Deactivate(); |
195 iCoeEnv->WsSession().Flush(); | |
196 } | |
197 | |
198 void CDemoCubeAppView::CameraReady() | |
199 { | |
200 iCamera->StartFeedL(); | |
201 } | |
202 | |
203 void CDemoCubeAppView::SetCameraFrame(CFbsBitmap& aBitmap) | |
204 { | |
205 BitmapDownScale(aBitmap); | |
206 | |
207 if(!iCamus) | |
208 { | |
209 iCamus = CCamus::NewL(*iCamusImage, 5); | |
210 iOpticalFlow = COpticalFlow::NewL(iCamusImage->Size()); | |
211 } | |
212 | |
213 iCamus->GetOpticalFlow(*iOpticalFlow, *iCamusImage, CAMUS_SETCAMUSOPTS(CCamus::EMedium, CCamus::EMedium, 3)); | |
214 CEgoMovement mean = iOpticalFlow->Mean(); | |
215 iMove.iX -= mean.iX * 6.3; | |
1
0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
216 iMove.iY -= mean.iY * 6.3; |
0 | 217 iAngle += iOpticalFlow->Rotation().Real() * 10.5; |
218 | |
219 // | |
220 iCubeWidth += (TInt)(iOpticalFlow->Depth().Real() * 5); | |
221 iCubeWidth = Max(2, iCubeWidth); | |
222 iCubeWidth = Min(iCubeWidth, 40); | |
223 // | |
224 | |
225 | |
226 iCube->Calculate(*iCubePoints, (TInt)iMove.iX.Real(), (TInt)iMove.iY.Real(), (TInt)iAngle, iCubeWidth); | |
227 | |
228 Draw(aBitmap, iCubePoints); | |
229 } | |
230 | |
231 void CDemoCubeAppView::BitmapDownScale(CFbsBitmap& aOriginal) | |
232 { | |
233 const TInt xBlockSize = aOriginal.SizeInPixels().iWidth / iBitmapSize.iWidth; | |
234 const TInt yBlockSize = aOriginal.SizeInPixels().iHeight / iBitmapSize.iHeight; | |
235 | |
236 TRgb color; | |
237 TPoint pos(0, 0); | |
238 | |
239 CPixelAccess* pa = CPixelAccess::NewLC(iCamusImage); | |
240 | |
241 | |
242 for(TInt y = 0; y < iBitmapSize.iHeight; y++) | |
243 { | |
244 for(TInt x = 0; x < iBitmapSize.iWidth; x++) | |
245 { | |
246 TInt red = 0; | |
247 TInt green = 0; | |
248 TInt blue = 0; | |
249 | |
250 for(TInt j = 0; j < yBlockSize; j++) | |
251 { | |
252 for(TInt i = 0; i < xBlockSize; i++) | |
253 { | |
254 pos.SetXY(x * xBlockSize + i, y * yBlockSize + j); | |
255 aOriginal.GetPixel(color, pos); | |
256 red += color.Red(); | |
257 green += color.Green(); | |
258 blue += color.Blue(); | |
259 } | |
260 } | |
261 | |
262 pos.SetXY(x, y); | |
263 pa->SetPos(pos); | |
264 const TInt pixels = xBlockSize * yBlockSize; | |
265 color.SetBlue(blue / pixels); | |
266 color.SetGreen(green / pixels); | |
267 color.SetRed(red / pixels); | |
268 pa->SetRGB(color.Value()); | |
269 } | |
270 } | |
271 CleanupStack::Pop(pa); | |
272 delete pa; | |
273 } | |
274 | |
275 // End of File |