/* * wiigee - accelerometerbased gesture recognition * Copyright (C) 2007, 2008, 2009 Benjamin Poppinga * * Developed at University of Oldenburg * Contact: wiigee@benjaminpoppinga.de * * This file is part of wiigee. * * wiigee is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package org.wiigee.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import org.wiigee.logic.GestureModel; import org.wiigee.logic.HMM; import org.wiigee.logic.Quantizer; /** * This is a static class to support saving and loading complete gestures. I've * choosen not to use some kind of XML, because the big multidimensional arrays * would cause a huge senseless amount of xml-data. So KISS: Keep It Simple, * Stupid! ;) Comma-separated-vectors with some control data. * * @author Benjamin 'BePo' Poppinga * */ public class FileIO { public static void writeToFile(GestureModel m, String name) { try { // initialize file and get values BufferedWriter out = new BufferedWriter(new FileWriter(name+".txt")); int numStates = m.getNumStates(); int numObservations = m.getNumObservations(); double defaultProbability = m.getDefaultProbability(); Quantizer quantizer = m.getQuantizer(); HMM hmm = m.getHMM(); out.write("# numStates:"); out.newLine(); out.write(Integer.toString(numStates)); out.newLine(); out.write("# numObservations:"); out.newLine(); out.write(Integer.toString(numObservations)); out.newLine(); out.write("# defaultProbability:"); out.newLine(); out.write(Double.toString(defaultProbability)); out.newLine(); out.write("# Quantizer: Radius"); out.newLine(); out.write(Double.toString(quantizer.getRadius())); out.newLine(); out.write("# Quantizer: MAP"); out.newLine(); double[][] map = quantizer.getHashMap(); for(int v=0; v