Hello.
The problem is most likely because you are trying to load a Hugin class description or hkb-file as a flat network file.
The code in example 4 'Load and inspect a network in a Windows.Form application' expects a flat network file.
This can be seen by looking at which of the overloaded constructors that is used for creating the runtime domain:
Domain(String, ParseListener) Constructs a domain from a NET file.
You could take the Easy solution:
The default behavior from the Hugin GUI is to save a network as a class-description. You should save the network as a flat net-file from the Hugin GUI application. (Save As.., then select *.net in the 'files of type' dropdown). The example code should be able to load the file.
...Or you could Implement a custom ParseListener:
Unfortunately the example doesn't implement a parseError-function. You could implement your own ParseListener and have the error description displayed in a MessageBox.
1) Add a subclass to the HuginControl-class:
public class HuginControl : System.Windows.Forms.Panel
{
[...]
public class MyParseListener : ParseListener {
public void ParseError(size_t position, String msg) {
MessageBox.Show("Parse error:\n" +msg + "\nAt line: " + position);
}
}
[...]
}
2) Use the custom ParseListener when loading the network. Replace the line:
Domain dom = new Domain(path, new DefaultClassParseListener());
with
Domain dom = new Domain(path, new MyParseListener());
I hope this helps.
(PS: Loading networks from hkb or class-descriptions: A class description should be loaded using a ClassCollection and then passing the corresponding class to the Domain constructor. A hkb-file is loaded using the Domain(String) constructor.)