001: /*
002: * Apollo - Motion capture and animation system
003: * Copyright (c) 2005 Apollo
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: * http://www.gnu.org/copyleft/gpl.html
020: *
021: * @author Giovane.Kuhn - brain@netuno.com.br
022: *
023: */
024: package org.apollo.view;
025:
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028: import java.awt.event.ItemEvent;
029: import java.awt.event.ItemListener;
030: import java.io.File;
031: import java.io.IOException;
032:
033: import javax.swing.JButton;
034: import javax.swing.JCheckBox;
035: import javax.swing.JComboBox;
036: import javax.swing.JLabel;
037: import javax.swing.JSplitPane;
038:
039: import org.apollo.ApolloUtil;
040: import org.apollo.bvh.BVHFile;
041: import org.apollo.bvh.BVHGenerator;
042: import org.apollo.bvh.Motion;
043: import org.apollo.datamodel.MotionVideo;
044: import org.apollo.datamodel.Video;
045: import org.apollo.i18n.ApolloResource;
046: import org.apollo.motion.DataGenerator;
047: import org.apollo.motion.MotionGenerator;
048: import org.apollo.player.BVHPlayerPanel;
049:
050: /**
051: * Panel to show video track using markers.
052: *
053: * @author Giovane.Kuhn on 28/04/2005
054: */
055: public final class AnimationPanel extends PropertyPanel implements
056: IVideoHandler {
057:
058: private static final long serialVersionUID = 1L;
059:
060: /** Panel to view tracking */
061: protected final BVHPlayerPanel playerPanel;
062:
063: /** Data format combo */
064: private final JComboBox dataCombo;
065:
066: /** Camera view combo */
067: private final JComboBox cameraCombo;
068:
069: /** Video that was be showed */
070: private Video video;
071:
072: public AnimationPanel(Video video) {
073:
074: // data generator
075: PropertyPanel right = new PropertyPanel();
076: right.add(new JLabel(ApolloResource
077: .getText("panel.animation.label.datagenerator")),
078: REMAINDER_POSITION, 1, WIDTH_RESIZABLE);
079: right.add(dataCombo = new JComboBox(DataGenerator.REGISTERED
080: .keySet().toArray()), REMAINDER_POSITION, 1,
081: WIDTH_RESIZABLE);
082: JButton button;
083: right.add(button = new JButton(ApolloResource
084: .getText("panel.animation.button.generate")),
085: REMAINDER_POSITION, 1, WIDTH_RESIZABLE);
086: button.addActionListener(new ActionListener() {
087:
088: public void actionPerformed(ActionEvent e) {
089: generate();
090: }
091:
092: });
093:
094: // show all joints
095: JCheckBox check;
096: right.add(check = new JCheckBox(ApolloResource
097: .getText("panel.animation.label.alljoints")),
098: REMAINDER_POSITION, 1, WIDTH_RESIZABLE);
099: check.setSelected(true);
100: check.addActionListener(new ActionListener() {
101:
102: public void actionPerformed(ActionEvent e) {
103: playerPanel.showAll(!playerPanel.isShowingAll());
104: }
105:
106: });
107: // camera view
108: right.add(new JLabel(ApolloResource
109: .getText("panel.animation.label.cameraview")),
110: REMAINDER_POSITION, 1);
111: right.add(cameraCombo = new JComboBox(CameraView.REGISTERED),
112: REMAINDER_POSITION, 1, WIDTH_RESIZABLE);
113: cameraCombo.addItemListener(new ItemListener() {
114:
115: public void itemStateChanged(ItemEvent e) {
116: changeCameraView();
117: }
118:
119: });
120:
121: // animation speed
122: right.add(new JLabel(ApolloResource
123: .getText("panel.animation.label.speed")),
124: REMAINDER_POSITION, 1);
125: right.add(button = new JButton(ApolloResource
126: .getText("panel.animation.button.speedslower")), 1, 1,
127: WIDTH_RESIZABLE);
128: button.addActionListener(new ActionListener() {
129:
130: public void actionPerformed(ActionEvent e) {
131: playerPanel.decSpeed();
132: }
133:
134: });
135: right.add(button = new JButton(ApolloResource
136: .getText("panel.animation.button.speedfaster")),
137: REMAINDER_POSITION, 1, WIDTH_RESIZABLE);
138: button.addActionListener(new ActionListener() {
139:
140: public void actionPerformed(ActionEvent e) {
141: playerPanel.incSpeed();
142: }
143:
144: });
145: right.add("", REMAINDER_POSITION, 1, BOTH_RESIZABLE);
146:
147: // split
148: JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
149: split.setRightComponent(right);
150: split.setLeftComponent(playerPanel = new BVHPlayerPanel());
151: split.setOneTouchExpandable(true);
152: this .add(split, BOTH_RESIZABLE);
153:
154: changeVideo(video);
155: }
156:
157: /* interface implementation */
158: public void close() {
159: changeVideo(null);
160: }
161:
162: public void refresh() {
163: changeCameraView();
164: }
165:
166: public void changeVideo(Video v) {
167: if (video == v) {
168: return;
169: }
170: this .video = v;
171:
172: // update player and panels
173: playerPanel.setVideo(v);
174: changeCameraView();
175: }
176:
177: public Object getSelectedObject() {
178: return null;
179: }
180:
181: /* interface implementation */
182:
183: /** Generate motion video, that contais BVH file */
184: protected void generate() {
185: if (video == null
186: || video.getTrackingVideo() == null
187: || //
188: video.getTrackingVideo().getFittedModelRoot(false) == null
189: || //
190: dataCombo.getSelectedItem() == null) {
191: return;
192: }
193: // create motion
194: Class dataGenerator = DataGenerator.REGISTERED.get(dataCombo
195: .getSelectedItem());
196: MotionGenerator mg = new MotionGenerator(video);
197: Motion m = mg.generate(DataGenerator.getInstance(dataGenerator,
198: video.getTrackingVideo()));
199:
200: // create bvh file
201: String projectPath = ApolloUtil.getPathName(video.getProject()
202: .getProjectFile());
203: String fileName = projectPath
204: + File.separatorChar
205: + ApolloUtil.getFileName(video.getRelativeVideoFile(),
206: false) + "_"
207: + video.getProject().getProjectName() + ".bvh";
208: BVHFile file = new BVHFile(video.getTrackingVideo()
209: .getFittedModelRoot(false), m);
210: BVHGenerator bg = new BVHGenerator(file, new File(fileName));
211: try {
212: bg.generate(true);
213: } catch (IOException e) {
214: throw new RuntimeException(e);
215: }
216:
217: // create motion video
218: MotionVideo mv = new MotionVideo();
219: mv.setRelativeBVHFile(ApolloUtil.getRelativeFileName(
220: projectPath, fileName));
221: video.setMotionVideo(mv);
222:
223: // save project
224: ApolloFrame.getInstance().save(video.getProject());
225: playerPanel.reset();
226: refresh();
227: }
228:
229: /** Change renderer camera view */
230: protected void changeCameraView() {
231: if (video == null || video.getMotionVideo() == null
232: || cameraCombo.getSelectedItem() == null) {
233: return;
234: }
235: // calculate camera view, for this video
236: CameraView cv = (CameraView) cameraCombo.getSelectedItem();
237: playerPanel.changeCameraView(cv.calculateCameraView(video));
238: refreshRenderer();
239: }
240:
241: /** Refresh renderer display */
242: protected void refreshRenderer() {
243: if (playerPanel == null) {
244: return;
245: }
246: playerPanel.refreshDisplay();
247: }
248: }
|