Masaryk University Faculty}w¡¢£¤¥¦§¨  of Informatics !"#$%&'()+,-./012345

Visualization of 3D Architectural Models on Apple iOS Platform

Bachelor Thesis

Martin Škrovina

Brno, Autumn 2015 Declaration

Hereby I declare, that this paper is my original authorial work, which I have worked out by my own. All sources, references and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source.

Martin Škrovina

Advisor: RNDr. Jaroslav Škrabálek

ii Acknowledgement

I would like to thank my supervisor, RNDr. Jaroslav Škrabálek, for providing me a thesis topic of my interest and his personal attitude to our cooperation.

iii Abstract

The objective of this thesis is to implement an application for vi- sualization of architecture models. The application implemented targets Apple iOS platform. The thesis deals with possibilities of real time visualization of building information models. The application supports loading and navigating in architectural models in IFC for- mat, which is used in Building Information Modeling — BIM. The thesis studies the data formats of the models and examines existing visualizing applications. The creation of the application, as well as the modifications of the utilized frameworks and components, are further discussed. Finally, the final application is tested for performance.

iv Keywords iOS, Objective C++, OpenSceneGraph, OpenGL ES, IfcPlusPlus, IFC, Building Information Modeling, BIM

v Contents

1 Introduction ...... 1 2 of the Models ...... 3 2.1 Generating Applications ...... 3 2.2 IFC ...... 3 2.2.1 Information Modeled By IFC...... 4 2.2.2 File Structure of IFC-SPF...... 5 3 Existing Available Applications and Components ...... 7 3.1 Architecture Visualizers on iOS ...... 7 3.1.1 BIMx...... 7 3.1.2 Tekla Field3D...... 8 3.2 IFC Libraries ...... 9 3.2.1 IfcOpenShell...... 9 3.2.2 Assimp...... 9 3.2.3 IfcPlusPlus...... 10 4 Implementation of the iOS Viewer ...... 14 4.1 Development environment ...... 14 4.2 Reuse of IfcPlusPlus ...... 15 4.3 Architecture of the IfcPlusPlusViewer ...... 17 4.3.1 Submodule cmd ...... 17 4.3.2 Submodule viewer ...... 18 4.3.3 Submodule gui ...... 18 4.3.4 Files Unassigned to a Submodule...... 19 4.4 Architecture of the IFCViewer ...... 19 4.5 Changes to the IfcPlusPlusViewer Contained in IFCViewer 22 4.5.1 Removal of the Dependency...... 22 4.5.2 UI Event Handling...... 23 4.5.3 Open Issues...... 23 4.6 Optimizations of the Imported Scene Graph ...... 24 5 Performance Test ...... 25 5.1 Test Methods ...... 25 5.2 Test Data ...... 25 5.3 Test Results ...... 26 6 Conclusion ...... 28 A Test Models ...... 35 B MultiTouchOrbit3DManipulator Source Code Example .. 37

vi 1 Introduction

In the past, architectural design was initially done on paper. The need for a formal definition of the design was fulfilled by providing techni- cal drawings along with the design in the paper form. Physical models of the building were built to help visualize the model and compare it to the intended result as the design and realization progressed. The aforementioned techniques are still used today. However, in the recent years, the building industry, just as many others, has begun to change under the influence of the emerging computer industry. The use of computers in design is often referred to as CAD1 or in the context of architecture as CAAD2.[1] Moreover, tools for definition of the technical formal specification, as well as the visual design, have been developed. Building information modeling, or BIM, is a process of building model creation, which covers physical and functional information of a building. [2] BIM tools are designed to also allow inter-operation between separate parts taking part in the building process. A few of these in- clude architecture, construction, mechanical, electrical and plumbing services, property management, infrastructure and many others. [2] All of these areas incrementally constitute to the BIM model of the project. It is often a requirement to deliver a BIM model along with other forms of documentation to a client such as the government. But in practice, BIM models are frequently created even for projects of much smaller scale, such as apartment houses or even family houses. The aim of this thesis is to implement a mobile application for vi- sualization of architecture models. Specifically, the application should be capable of navigating 3D models of buildings. The application could then be used by architects, builders or anyone involved in the building industry working with BIM models, to get familiar with the appearance of the building model using their mobile devices. The theoretical part of this thesis first deals with the analysis of BIM file formats. Furthermore, the available applications for iOS platform visualizing BIM models are considered. The ideas of these applications

1. Computer aided design 2. Computer aided architectural design 1 1. Introduction are taken for inspiration in the chapter 3.2, which evaluates the usability of the components for a potential reuse in the development of the intended application. The practical part discusses the implementation of the IFCViewer application for both iPad and iPhone devices and points out the greatest challenges of the application development. It discusses the incorporation of the reused 3rd party components and presents solutions to problems that arose. In the end, the performance of the final application is tested. The results and findings of this thesis, as well as suggestions for possible extensions of the application, are summed up in the conclusion.

2 2 File Format of the Models

This chapter deals with the choice of the file format supported by the application built in the implementation part of the thesis. A research of applications generating the BIM models was done to ensure that the selected file format is universal. Further, this chapter discusses the selected file format.

2.1 Generating Applications

The architectural BIM models are usually generated by BIM modeling applications. Most popular desktop applications for architecture cre- ation and editing include Autodesk Revit [3], ArchiCAD [4], Tekla Structures [5] and VectorWorks [6]. [7] The openBIM initiative led by buildingSMART [8] defines set of standards for BIM. These standards are widely adopted by the building industry. [7] The standards are also implemented in the aforementioned modeling applications. The focus of the application built in this thesis is on the part of the standard that deals with data. Since IFC1 is one of the most popular and widely adopted BIM data modeling language2, it was chosen as the supported input format for the viewer application. The benefit of this decision is that it is highly probable that the users already have the architectural model in this format, so there would be no need for conversion.

2.2 IFC

IFC is an open data model designed for building and construction data description. IFC is itself an international official ISO Standard registered as ISO16739. [9] It utilizes several other standards in its specification. IFC models are described in EXPRESS data definition language. The IFC format is defined by an EXPRESS schema. The schema describes possibilities of modeling data and relationships between them.

1. Industry Foundation Classes 2. Depending on the support of popular applications [7]

3 2. File Format of the Models

EXPRESS data modeling language is a standard formalized in the ISO Standard for the Exchange of Product model STEP. [10] Moreover, STEP defines file formats recommended for storage and interchange of EXPRESS models. STEP formats adopted by Industry Foundation Classes are STEP- File and STEP-XML, which are used by IFC-SPF and IFC-XML respec- tively. [8] STEP-XML versions of the same file are larger than the STEP-File equivalents due to the XML formatting overhead. Therefore, IFC-SPF is the most ubiquitous data exchange form of IFC. [8]

2.2.1 Information Modeled By IFC IFC defines entity-relationship model, which consists of several hun- dreds of standard entities. The built viewer application gives focus on visualization of the architectural construction data. The architectural data is modeled by following IFC entities:

• Products are modeled by the root class IfcProduct, which is the base class for all physical objects. The subclasses thereof can be divided into 2 categories of elements:

– Spatial ∗ IfcSite ∗ IfcBuilding ∗ IfcBuildingStorey ∗ IfcSpace – Physical ∗ IfcWall ∗ IfcBeam ∗ IfcDoor ∗ IfcWindow ∗ IfcStair ∗ etc...

4 2. File Format of the Models

• Relationships are modeled through the IfcRelationship class. The possible relationships between classes are composition, assignment, connectivity, association and definition. Particularly important relationships for architecture modeling and their examples are:

– Composition – IfcBuilding as a composition of IfcBuilding- Storey instances – Connectivity – IfcSlab connected to an IfcBeam – Association – IfcMaterial associated to an IfcProduct – Definition – IfcFurnishingElement to be defined with non- standard properties of some IfcPropertySet

The shape of a physical element is associated to a product via IfcShapeRepresentation. The geometry can be represented by CSG3, B-rep4, NURBS5 or swept profiles. [11]

2.2.2 File Structure of IFC-SPF STEP-File is a textual ASCII structured format. It is well readable, yet concise. However, IFC-SPF models can still easily grow to sizes of hundreds of megabytes and even gigabytes when information from more sources is to be modeled. The IFC-SPF file is divided into header and data section. The header section states information about the authors, format specification used and gives a quick overview of the project as documented in the figure 2.1.[11] The data section illustrated in figure 2.2 defines all the instances of the IFC entities. Each instance has a file scoped unique STEP ID, entity type name and list of explicit attribute. [11]

3. Constructive solid geometry 4. Boundary representation 5. Non-uniform rational B-spline

5 2. File Format of the Models

HEADER; FILE_DESCRIPTION((' IFC 2x platform '),'2;1');FILE_NAME( 'Example.dwg ', '2005-09-02T14:48:42 ' , ('The User '), ('The Company '), 'The name and version of the IFC preprocessor ', 'The name of the originating software system ', 'The name of the authorizing person '); FILE_SCHEMA((' IFC2X2_FINAL ')); ENDSEC;

Figure 2.1: IFC-SPF header example [11]

DATA; #7=IFCCARTESIANPOINT((0.,0.,0.)); #8=IFCDIRECTION((0.,0.,1.)); #9=IFCDIRECTION((1.,0.,0.)); #10=IFCAXIS2PLACEMENT3D(#7,#8,#9); ENDSEC;

Figure 2.2: IFC-SPF data section example defining a point in a 3D space ona2D axis [11]

6 3 Existing Available Applications and Compo- nents

First, this chapter discusses my findings of available applications for iOS platform that could be a source of inspiration for the created IFCViewer application. Second, research of the available libraries and components is presented and summed, resulting in a selection used in the implementation part.

3.1 Architecture Visualizers on iOS

Model visualization is usually a byproduct of an application. The viewing capability is naturally built into applications processing IFC such as the architectural applications mentioned in the section 2.1. The research for iOS applications was done on the iOS AppStore, since it is the place for distribution of all public applications for the iOS platform. Two exemplary applications are shown in this chapter.

3.1.1 BIMx

BIMx1 is a platform for architectural model sharing between stake- holders in BIM — primarily architects and clients. Along the desktop application, BIMx platform also covers iOS platform with an application [12] of the same name. Users have to export models from ArchiCAD in a proprietary BIMx format in order to use them in the BIMx application. Graphisoft refers to the BIMx models as “hypermodels”, meaning they are capable of combining 2-dimensional and 3-dimensional plans into a single model. The BIMx format is the only supported format and the application doesn’t support direct import of IFC files.

1. http://www.graphisoft.com/bimx/

7 3. Existing Available Applications and Components

Figure 3.1: BIMx iOS application displaying a first-person look inside a sample building model

3.1.2 Tekla Field3D

Tekla Field3D [13] was the only iOS application found on the AppStore that supported on-device IFC model loading. The mobile application constitutes to the Tekla’s BIM platform by offering connection to their cloud where users can upload their models. Field3D is shareware. The full version is capable of showing chosen object properties, hiding selected objects or whole layers, making them transparent, clipping the whole model by a plane, commenting loca- tions, measuring distances and searching for objects with particular properties. The free version does not support any of these features and limits the user to viewing and navigating the 3D model.

8 3. Existing Available Applications and Components

Figure 3.2: Tekla Field3D previewing model AC11-FZK-Haus-IFC [14]

3.2 IFC Libraries

This section discusses libraries, that support reading IFC models, that could be used in development of a native iOS application.

3.2.1 IfcOpenShell IfcOpenShell is an open-source for reading and writing IFC models. [15] IfcOpenShell uses Open CASCADE Technology [16] for the explicit geometry creation. [15] Brief testing resulted in IfcOpenShell being slower than the other available libraries discussed below.

3.2.2 Assimp Open Asset Import Library, or Assimp, is a portable C++ library for importing 3D models of various formats. [17] Its main target is to

9 3. Existing Available Applications and Components provide a full asset conversion pipeline for use in real-time rendering systems. Assimp claims to support loading from IFC-SPF format. [18] The stable release (3.1.1) of the library was tested with a few simple sample IFC models. None of these models could be successfully loaded. Following, the development branch was examined and the bug had been fixed in the development branch. The loaded scene is represented in Assimp by aiScene. The scene can have a tree structure such as in the case of IFC geometry storing. However, all of the IFC spatial information about the tree node, aiNode, is stored in the name string of the node. The inaccessibility to the structured model data is limiting for the possible extensions of architectural viewers. On the contrary, the Assimp library is fast — especially when compared to the IfcOpenShell.

3.2.3 IfcPlusPlus IfcPlusPlus [19] is an open source library written in C++. It serves as a reader and writer of IFC files in STEP format (IFC-SPF). The library is compliant with the IFC2x3 and IFC4 specifications. Furthermore, it allows extension to other specifications by using the IfcPlusPlusExten- der[20] tool. IfcPlusPlus is developed to be multi-platform. A viewer appli- cation, IfcPlusPlusViewer, is part of the IfcPlusPlus package. It is capable of viewing and navigating an IFC model. Furthermore, it can display and link the hierarchy of physical model parts to their visual representations and selectively hide them. The application IFCViewer, developed in the implementation part, utilizes the IfcPlusPlus library, as well as the IFCPlusPlusViewer application.

Libraries Used by IfcPlusPlus The library takes advantage of following third-party libraries:

Carve [22] is a free2 software C++ library for constructive solid geometry. It is designed to perform boolean operations such as union, intersection or difference on polygonal meshes.

2. As defined by The Free Software Foundation 10 3. Existing Available Applications and Components

Figure 3.3: IfcPlusPlusViewer [21] built and running on OS X 10.10 previewing model AC11-FZK-Haus-IFC [14]

OpenSceneGraph [23] is a multi-platform graphics scene graph library implemented in C++. Scene graph libraries provide an ability of abstracting the work with graphics 3. Work with graphics APIs such as OpenGL consists of a stream of primitive drawing commands (draw polygon, line, point, etc.), state settings (set color, texture, etc.) and matrix ma- nipulations (push/pop to model-view or perspective matrix, etc.) [24]. These APIs, however, contain very little information that allows the system to self-optimize and improve performance [24]. In a scene graph, objects in a scene are logically grouped together into a hierarchy to form a tree. When manipulating the parent nodes, the changes propagate into children. Moreover, properties of the parent nodes are inherited by the children and can be overridden. The geometry data is usually contained in the leaf nodes. When nodes with very same characteristics are to be used multiple times in the

3. Application programming interface

11 3. Existing Available Applications and Components

scene, they can be referenced as children of multiple nodes. This is a common optimization and makes the hierarchical structure a graph, thus scene graph. The current stable release of OpenSceneGraph (3.2.1) supports OpenGL 1.0 through to OpenGL 4.2, and OpenGL ES 1.1 and 2.0 [23].

Qt [25] is a cross-platform framework for application development. Qt exhibits APIs for building graphical user interfaces. The primary elements for creating UIs in Qt are called widgets [26]. Examples of a widget include application window, panel, button or label. Even though, it is possible to develop iOS applications in Qt framework, the Qt doesn’t provide any means for incorporating native iOS UI4 elements into the Qt UI.

IfcPlusPlus Modules The IfcPlusPlus library consists of 3 main modules: IfcPlusPlus, IfcPlusPlusGeometry and IfcPlusPlusViewer

IfcPlusPlus is the module responsible for reading and writing IFC- SPF file into and from a C++ object represented by IfcPPModel class, respectively. The IFC schema is represented by C++ classes. Since the EXPRESS modeling language is object oriented, the conversion to the C++ is rather straightforward. A total of 1157 classes are used to repre- sent the IFC4 schema classes. The interest of the viewer application is, naturally, predominantly in the model reading capabilities. The IFC entities are represented by IfcPPEntity subclasses.

IfcPlusPlusGeometry is responsible for transformation of the IfcPPModel into a scene graph. It uses the Carve library to construct meshes from IfcProducts. These meshes of a product are then added as a geometry to a drawable OpenSceneGraph geometry node, referred to as Geode. The material containing color and shininess is further added to the Geode depending on the processed entity.

4. User interface

12 3. Existing Available Applications and Components

IfcPlusPlusViewer is the module, in which the user interface and viewing interactions are contained. It represents the whole GUI appli- cation. IfcPlusPlusViewer utilizes IfcPlusPlusGeometry to import a OSG5 scene graph. The scene graph is visualized by a subclass of an OSG Viewer. Navigation interactions around the model such as rotation, translation and scale are handled with help of a custom OSG CameraManipulator. The user interface is implemented using the Qt toolkit.

5. OpenSceneGraph

13 4 Implementation of the iOS Viewer

This chapter discusses the implementation of the viewer application, further referred to as IFCViewer. The OS X compatible version [21] of IfcPlusPlus maintained and kept in synchronization with the main IFCPlusPlus project [19] was used as a basis for the viewer part of the IFCViewer.

Figure 4.1: IFCViewer application previewing model AC11-FZK-Haus-IFC [14]

4.1 Development environment

Standard iOS development tools were used to create the IFCViewer. Xcode was used as the IDE1, as well as the build system for the IFCViewer and libraries. The viewer part is contained in a separate framework — IFC3DViewer — which is linked dynamically to the IFCViewer application target. IFCViewer targets iOS version 8.0 and runs on both iPhone and iPad devices. The IFCPlusPlus, OSG, Carve and boost libraries are built statically, so supporting iOS 7.0 version is possible, if desired without rebuilding these libraries. However, to provide the support, the IFC3DViewer framework would have

1. Integrated development environment

14 4. Implementation of the iOS Viewer

to be statically built too. But, since the IFC3DViewer contains other resources than code, such as the user interface XIB file, an additional re- source bundle would have to be distributed with a static IFC3DViewer library. The application was developed in Objective-C, C++ and Objective- C++ programming languages. The C++ code is used in the visualizing part of the application that supplements the incorporated IFCPlusPlus libraries. Objective-C was used to utilize the iOS CocoaTouch system frameworks for user interface (UIKit framework), as well as, general programming in the client application of the IFC3DViewer framework, the IFCViewer. In the areas, where inter-operation of Objective-C and C++ code was needed, Objective-C++ was used. The implementation was continuously tested on an iPhone 5C [27] device running iOS version 8.

4.2 Reuse of IfcPlusPlus

The packages of IfcPlusPlus were first analyzed for dependencies possibly unsupported on iOS. This section discusses the compatibility of the modules with the iOS platform.

Module IfcPlusPlus

IfcPlusPlus requires the popular C++ extension library — Boost [28], which is meant to be highly portable. So its also available on the iOS platform. Further, the IfcPlusPlus takes advantage of OpenMP [29] to parallelize the loading of the model in IfcPPReaderSTEP class. However, the current version of the iOS compiler, Clang2, does not support OpenMP. OpenMP support is not mandatory for use of IfcPlusPlus but as a consequence, the sections taking advantage of OpenMP are not parallelized in the IFCViewer. The IfcPlusPlus module could be built into a static library with aforementioned limitations.

2. Apple LLVM Clang version 602.0.49

15 4. Implementation of the iOS Viewer

Module IfcPlusPlusGeometry IfcPlusPlusGeometry uses OpenMP to parallelize geometry creation in ReaderWriterIFC. As in the case of IfcPlusPlus, the OpenMP support is dropped in the IFCViewer. IfcPlusPlusGeometry also utilizes the Boost library. Another dependency, the Carve library used for CSG3 is portable to iOS too. Last, the OSG4 can be embedded into a native iOS application. Running on iOS, it can take advantage of either OpenGL ES 1.1 or 2.0. However, the APIs of the desktop and the mobile version are not fully compatible due to the difference in the underlying OpenGL APIs. The IfcPlusPlusViewer employs the so called OpenGL fixed func- tion graphics pipeline through the OSG. However, the fixed function pipeline is unsupported on OpenGL ES 2. Therefore, the OSG library was built with the OpenGL ES 1.1 support and the IFCViewer contin- ues to make use of the fixed function pipeline. Eventually, no modifications had to be done to the IfcPlusPlusGeometry since no incompatibility issues arose.

Module IfcPlusPlusViewer The IfcPlusPlusViewer is dependent on the Qt toolkit. The use of Qt is undesired for a modular iOS application, whose parts should be easily incorporated into some other application. Qt toolkit components are used predominantly for 3 purposes in the IfcPlusPlusViewer. The first purpose is the creation of the whole . Qt widgets were used to model the application window (MainWindow), the viewer panel (ViewerWidget), the hierarchical struc- tured list on the right hand side (IfcTreeWidget), and the tabs con- tained in the bottom panel for file reading control and viewer option setting (TabReadWrite and TabView respectively). The second purpose is the communication between objects using signals and slots. For this purpose, lots of objects are made instances of QObject, which is the Qt base class for the signal and slot support. Last, is the realization of an OSG Viewer using the special Qt com-

3. Constructive solid geometry 4. OpenSceneGraph

16 4. Implementation of the iOS Viewer patible graphics context container, the osgQt::GraphicsWindowQt. The removal and substitution of the dependency on the Qt toolkit is described in the subsection 4.5.1 Next, the IfcPlusPlusViewer utilizes the OSG library. The use of OSG is partially incompatible in the Orbit3DManipulator class due to the difference in the way of interaction with the device since iOS devices use touchscreen instead of mouse. More, some OpenGL state settings are not available in the OpenGL ES 1.1, hence in the IFCViewer. The solutions of these incompatibilities are described in the sub- section 4.5.3.

4.3 Architecture of the IfcPlusPlusViewer

In order to modify the IfcPlusPlusViewer to suit iOS platform, the module had to be analyzed first. The IfcPlusPlusViewer is divided into 3 logical submodules and 2 unassigned classes, as well as the main file. The source files of the submodules are contained in sub-folders with the submodules’ respective names. This section discusses the original architecture of the subset of IfcPlusPlusViewer that is used by the IFCViewer.

4.3.1 Submodule cmd

Submodule cmd uses the command design pattern and groups the communication with the data model by executing commands. CommandManager takes care of execution of these commands. The commands are represented by subclasses of Command. The commands serve purposes such as loading the IFC model into the applica- tion in form of the IfcPPModel and scene graph — osg::Group. The loading is covered by LoadIfcFileCommand. Another command, CmdRemoveSelectedObjects is responsible for removing the objects previously selected in the viewer from the scene graph. Since the IfcPlusPlusViewer application doesn’t attempt to alter the underlying IFC model, the removal of the selected object from the IfcPPModel is not necessary and is not done in the CmdRemoveSelectedObjects.

17 4. Implementation of the iOS Viewer

4.3.2 Submodule viewer

Submodule viewer groups the source files related to the model viewer. ViewerWidget is a Qt widget that owns a osgViewer::CompositeViewer. OSG provides osgViewer::Viewer to encapsulate the drawing — graph- ics context. In this case, the graphics context is realized with the osgQt::GraphicsWindowQt. An osgViewer::Viewer can hold one or in case of osgViewer::CompositeViewer more osg::Views [30]. The osgViewer::View of the osgViewer::CompositeViewer holds a single view on the scene. The camera of the osgViewer::View is manipulated using an object of Orbit3DManipulator. Orbit3DManipulator is an OSG camera manipulator. The Orbit3DManipulator changes the position of the camera of the osgViewer::View. It does so based on the user interaction. Since IfcPlusPlusViewer is a desktop application, the interaction happens through the mouse and keyboard input. Orbit3DManipulator uses the lookat abstraction to set the camera position in the 3D space. A drag with a left button mouse click induces the rotation of the camera around the model. First, a ray is cast into the scene. Then, with mouse dragging, the camera is rotated around the point intersecting the geometry. Zooming is controlled by a mouse scroll wheel. The camera is translated in the direction of the cast ray with amount dependent on the intersection distance. Panning is accomplished by dragging with right mouse button. The movement vector from the screen is unprojected to the world space. Then, the camera is translated by the unprojected vector. An object in a scene represented by a osg::Geode is selected by clicking on it with a mouse. Again, a ray is cast into the scene and the intersecting geometry node is found. The node is then highlighted using a osgFX::Scribe effect to provide feedback to the user.

4.3.3 Submodule gui

Submodule gui contains the Qt widget subclasses. The whole appli- cation window is represented by the MainWindow. The MainWindow references and owns the remaining widgets, as they are visually

18 4. Implementation of the iOS Viewer

contained inside of it. TabReadWrite widget creates a LoadIfcFileCommand with a path to the source IFC file. The command is passed the IfcPlusPlusSystem. The IfcPlusPlusSystem is supplied the read model (IfcPPModel and osg::Group) upon successful execution.

4.3.4 Files Unassigned to a Submodule IfcPlusPlusSystem

From the perspective of the MVC 5 design pattern, the IfcPlusPlus- System serves as a controller class. First, it is the handler of the GUI events in the application. Second, it remembers the selection of the objects in the scene and handles the removal of the selected object, if triggered.

ViewController

The ViewController is the class which controls the general drawing settings of the scene. It sets up the lighting and default materials for the objects of the scene.

4.4 Architecture of the IFCViewer

The IFCViewer uses a modified version of the IfcPlusPlus for the model viewing capabilities. The architecture of the modified IfcPlusPlus module was kept close to the original architecture. This was done in belief, that it would make it easy to keep the IFCViewer in sync with the development of IfcPlusPlus and possibly encourage developers familiar with the IfcPlusPlus to the development of the IFCViewer. The flow of the view controllers in the application is designed in the Main.storyboard file.

5. Model View Controller

19 4. Implementation of the iOS Viewer

Figure 4.2: Diagram of the most important IFCViewer components with example classes

Model loading The models are loaded into the IFCViewer by opening a IFC file via iOS action menu in other application such as file system browser, mail client or web browser. This support is declared in the application bundle’s Info.plist file. When the IFC file is opened from other application, the method application:openURL:options: is called on the App Delegate to pass the file URL to the application. The application copies the file toits documents folder. The list of models stored in the IFCViewer is controlled by UITableViewController subclass FileListTableViewController.

20 4. Implementation of the iOS Viewer

FileListTableViewController also controls deletion of the mod- els. The FileListTableViewController creates and presents a ARVViewController upon selection of a model file from the list.

Model viewer

The main part of the IFCViewer application is the model viewer. The model viewer was designed to be a modular component and its in- terface for Objective-C classes is contained in the ARVViewController class inside a separate dynamic framework –– IFC3DViewer.

ARVViewController

The ARVViewController is designed in a separate XIB file, aside of the storyboard to make it more reusable. The view controller appear- ance can thus be easily tweaked using the Xcode interface builder environment. ARVViewController provides very simple interface. The ARVView- Controller is to be passed a string with a filepath to IFC-SPF model file. The IFC model is then asynchronously loaded upon presentation of the view controller and continuously drawn on the screen. The CADisplayLink refreshes the OSG Viewer while the view controller’s view is in the view hierarchy.

ARVView

The view part was further separated from the model and controller part to a subclass of UIView — ARVView. The ARVView is used by the OSG Viewer as the drawing canvas. The ViewerWidget realizes the OpenGL view on the supplied ARVView. An ARVView is passed to the ViewerWidget in its constructor. ARVView uses a UIMenuController to display popup overlay when the model is tapped. The selected object can be hidden by choosing the “Hide” action from the popup. The popup menu is dismissed by tap- ping anywhere out of it in the view. ARVView delegates the hide action to its sceneManipulationDelegate, which is a ARVViewController.

21 4. Implementation of the iOS Viewer 4.5 Changes to the IfcPlusPlusViewer Contained in IFCViewer

This section discusses the changes that were made to the code partially shared with the desktop viewer application — IfcPlusPlusViewer.

4.5.1 Removal of the Qt Dependency In order to incorporate the functionality of the gui submodule of IfcPlusPlusViewer into the IFCViewer, the Qt dependency was re- moved. All of the classes used by ARVView, which had been subclasses of QObject, were made free of the QObject superclass. The former subclasses of the QObject, now included in the IFCViewer, were TabReadWrite and IfcPlusPlusSystem. The MainWindow was a QObject subclass. But its functionality was trans- ferred into the ARVViewController. The ViewerWidget in IfcPlusPlusViewer had used a GraphicsWindowQt as the osg::GraphicsContext. The context was substituted by creating a GraphicsWindowIOS with a custom supplied view, which is an ARVView. This way, the ARVView encapsulates the layout of the viewer and OpenGL drawing. The ARVView coexists well with other UIViews in the view hierarchy. That means, views can be placed over the ARVView or aside with no problems with touch handling or drawing. Before, the continuous update of the Viewer was ensured by the Qt widget ViewerWidget. Now, the Viewer is synchronized with the display frame rate using a timer, specifically, a CADisplayLink, in the ARVViewController. The Qt slots and signals notification system was replaced with callback oriented notification. What more, anonymous closures — blocks were used for this purpose. Since blocks are an extension of the C99 standard, they can be used in both Objective-C and C++ and hence of course Objective-C++. [31] The blocks are used as callbacks for object selection and loading progress. For asynchronous loading of the model on a background , GCD6 was used.

6. Grand Central Dispatch

22 4. Implementation of the iOS Viewer

4.5.2 UI Event Handling The Orbit3DManipulator supports handling of mouse events for manipulation with the camera around the model. However, the inter- action with applications on iOS is done using multi-touch gestures. The semantic of the gestures was chosen to be the same as in the applications tested in chapter3 to prevent confusion of the users. The desired gestures are: 1. Tap for selection of an object in the scene. 2. Single finger panning for rotation of the camera around point intersecting the model at the finger touch. 3. Two finger pinch gesture that controls zooming. The zoomis faster when the distance to the model is greater. 4. At the same time with the pinch, the user should have possibility to move the camera in direction perpendicular to the camera’s view direction by panning with two fingers. The model move- ment should track the fingers no matter how far the camera is. The single touch gestures were compatible with the original Orbit3DManipulator implementation. The multi-touch gesture support was implemented in the MultiTouchOrbit3DManipulator class, which is a subclass of Orbit3DManipulator. The MultiTouchOrbit3DManipulator is con- sulted for handling the UI events and redirects them to the superclass if multiple touches have not been detected. Commented code of the MultiTouchOrbit3DManipulator is at- tached in the appendix, partB.

4.5.3 Open Scene Graph Issues State settings, which were unsupported on OpenGL ES 1.1. were turned off and substituted, if necessary. Stippled lines arenot supported on ES 1.1. So the coordinate axes previously added in ViewController were simply removed. Also in the ViewController, the LightModel setting is un- supported. Instead, the ambient colors were enhanced in the

23 4. Implementation of the iOS Viewer

EqualizeColorVisitor upon model loading. All in all, the default OSG global illumination is sufficient for the application’s lighting purposes. Moreover the osgFX::Scribe effect applied on the selected node in the IfcPlusPlusSystem was substituted for a simple osg ::Group, SelectedGroup, which overrides the children material with its own of yellow color.

4.6 Optimizations of the Imported Scene Graph

The scene graph is optimized in the LoadIfcFileCommand with help of osgUtil::Optimizer. Default optimizations of the Optimizer are used right after the import. Optimizations include flattening of static transformations, removing the redundant nodes, sharing duplicate state, merging the geometry, simplifying the geometry, etc. [32, 33].

24 5 Performance Test

This chapter deals with the performance testing that was performed with the final build of the application. The tests measure overall responsiveness of the model viewer, as well as the load that the viewing puts on the device. The application performance was tested using the Xcode IDE tools for performance profiling — Instruments. The profiling session was attached to a release build of the IFCViewer.

Test Device

The testing device was an iPhone 5C running iOS 8.3. The device was released in September, 2013 [27]. It has 1GB of internal RAM memory and a dual-core 1.3 GHz processor [27].

5.1 Test Methods

The method for testing the responsiveness of the viewer was measur- ing the FPS count1. The load on system is monitored by the consumed memory. The loading time was noted too, since it also plays an important role in the user experience with the application. The FPS measurements were taken at different levels of zoom at the model. The stable minimum FPS counts were noted. This was done due to the optimizations of the OSG. OSG uses frustum culling and small feature culling. Therefore, the measurements would be distorted if measured from a single fixed position of the camera.

5.2 Test Data

Models of file size varying from 2.8 MB to 58.5 MB were tested. The first 7 models used for the performance test were downloaded from Open IFC Model Repository of The University of Auckland [34]. The last model – M8 – is a model from a test case in the IFCCompressor [35] project.

1. Frames per second 25 5. Performance Test

Model Figure Filesize #ent #nod #geod M1 [36] A.1a 2.8 MB 49663 4325 1775 M2 [37] A.1b 3.4 MB 62667 7171 3586 M3 [38] A.1c 4.1 MB 82333 3273 2855 M4 [39] A.1d 7.4 MB 127064 2718 1493 M5 [40] A.1e 14.6 MB 224470 1429 599 M6 [41] A.1f 18.4 MB 328567 39750 6970 M7 [42] A.1f 31.1 MB 515973 17308 6970 M8 [43] N/A 58.5 MB N/A N/A N/A

Table 5.1: The sample of the models tested

The table 5.1 lists all tested models. The #ent column states how many entities are read from the source file into the IfcPPModel. The #nod column informs about the number of osg::Node instances in the loaded scene graph. The #geod column states the count of drawable nodes — osg::Geodes in the loaded scene graph. Only the model M8 could not be successfully loaded into the application and hence some information could not be measured.

5.3 Test Results

Model Filesize RAM #ent #nod #geod FPS tload M1 2.8 MB 38 MB 49663 4325 1775 35 8 M2 3.4 MB 61 MB 62667 7171 3586 22 8.3 M3 4.1 MB 41 MB 82333 3273 2855 36 6.8 M4 7.4 MB 57 MB 127064 2718 1493 37 11.4 M5 14.6 MB 91 MB 224470 1429 599 60 24.6 M6 18.4 MB 147 MB 328567 39750 6970 12 38.4 M7 31.1 MB 217 MB 515973 17308 6970 12 60 M8 58.5 MB 610 MB N/A N/A N/A N/A N/A

Table 5.2: Results of the measurements

The table 5.2 describes the results of the testing measurements.

26 5. Performance Test

The tload stands for the duration of the model loading in seconds. The RAM column states the top bound amount of memory used while loading and viewing the particular file.

Graphics

A connection between the FPS count and #geod can be seen. It’s probably so because the number of OpenGL draw calls depends on the Geode count. The user experience is not much effected unless the FPS count drops below approximately 20 FPS. Manipulating the camera around models at 20–30 FPS was rather smooth. There were no problems with the simpler tested models (M1–M5). But the manipulation lagged occasionally in the more complicated models (M6, M7).

Memory The table also shows that the IFC files include a lot of information of non-geometry character. Models M8 and M9 share the same geometry classes but the latter packs more additional information. If possible, the models should be exported with as little extra information as possible. The 58.5 MB model could not be loaded into the memory. The iOS system killed the application after 60 seconds of loading, when the uti- lized memory was at 610 MB. As for the model loading times, it is not usual to wait for the completion of some task for 40 seconds on mobile devices, so the loading time should be kept under approximately 30 seconds.

Summary The IFCViewer is designed for viewing simple architectural models of file sizes about up to 15 MB and up to about 4000 Geodes. Then, sufficient user experience with the application can be maintained even on slightly older iOS devices on the market.

27 6 Conclusion

The thesis explores an area of architectonic models and Building Information Modeling. It takes advantage of the concepts of BIM and open-source components to build a simple BIM architecture model visualizer application for the iOS platform. The current trends of architectural modeling were described with respect to the form of the interchange of this kind of data. Furthermore, an overview of possibilities of BIM visualizers on iOS platform was done in order to help understand the current mobile application trends in the area. The promising open source libraries and applications were evaluated for their fitness for purposes of building a native iOS IFC viewer application. The most fitting ones were then chosen for the implementation part. With the application built in the implementation part, IFCViewer, users can view their simple architectural models stored in IFC file format. The application supports gesture based navigation in a BIM model. The navigation is eased by allowing removal of certain parts of the model. The library containing the viewer part — IFC3DViewer — provides a simple interface for straightforward incorporation into custom iOS applications. The application design and adaptations needed in order to utilize the reused 3rd party components were described in the chapter4. Since the IFCPlusPlus library was not well documented, it was quite hard to port the library to the iOS platform. The challenges of the porting process of IFCPlusPlus library were also discussed in this thesis. The resulting application from this thesis, IFCViewer, is capable of displaying and manipulating files containing 3D models of buildings reaching filesizes up to 15 MB. This finding is covered in the testing part of this thesis. Application supports basic functionality needed for the traversal of the models. There certainly is a space for improvements for the IFCViewer, as well as for extensions of the application. The shading of the models could be made more visually appealing and the viewer could be modified to use OpenGL ES 2.

28 6. Conclusion

Similarly, the IFCViewer does not yet take advantage of the BIM structural information. So in case some application needed to work with the structure data, an API for this purpose could be added to IFC3DViewer.

29 Bibliography

[1] Computer-aided architectural design. url: https://en.wikipedia.org/wiki/Computer- aided_architectural_design (visited on 04/04/2015). [2] BIM. url: http: //en.wikipedia.org/wiki/Building_information_modeling (visited on 04/04/2015). [3] Autodesk Inc. Revit. url: http://www.autodesk.com/products/revit- family/overview (visited on 04/04/2015). [4] GRAPHISOFT SE. ArchiCAD. url: http://www.graphisoft.com/archicad/ (visited on 04/04/2015). [5] Tekla Corporation. Tekla Structures. url: http://www.tekla.com/products/tekla-structures (visited on 04/04/2015). [6] Nemetschek Vectorworks, Inc. Vectorworks. url: http://www.vectorworks.net (visited on 04/04/2015). [7] Solibri Inc. About BIM and IFC. url: http://www.solibri.com/support/bim-ifc/ (visited on 04/04/2015). [8] buildingSMART. url: http://www.buildingsmart-tech.org (visited on 04/04/2015). [9] buildingSMART. IFC Overview summary. url: http://www.buildingsmart-tech.org/specifications/ifc- overview (visited on 04/04/2015). [10] ISO. ISO 10303-21:2002. url: http://www.iso.org/iso/home/store/catalogue_tc/ catalogue_detail.htm?csnumber=33713 (visited on 04/06/2015).

30 BIBLIOGRAPHY

[11] buildingSMART. IFC 2x Edition 3 Model Implementation Guide. url: http://www.buildingsmart- tech.org/downloads/accompanying-documents/guidelines/ IFC2x%20Model%20Implementation%20Guide%20V2-0b.pdf (visited on 04/06/2015). [12] BIMx. url: https://itunes.apple.com/app/bimx-building- information/id452706864?mt=8 (visited on 04/10/2015). [13] Tekla Field3D. url: https://itunes.apple.com/app/tekla- field3d/id868034113?mt=8 (visited on 04/09/2015). [14] Architect Building Designer Office. KIT: AC11-FZK-Haus-IFC | KIT: AC1-001. Nov. 30, 2010. url: http://openifcmodel.cs.auckland.ac.nz/Model (visited on 04/13/2015). [15] IfcOpenShell. url: http://ifcopenshell.org/index.html (visited on 04/09/2015). [16] Open CASCADE. url: http://www.opencascade.org (visited on 04/09/2015). [17] Open Asset Import Library. url: http://assimp.sourceforge.net (visited on 04/06/2015). [18] Open Asset Import Library. url: http: //assimp.sourceforge.net/main_features_formats.html (visited on 04/06/2015). [19] Fabian Gerold. IfcPlusPlus. url: http://www.ifcplusplus.com (visited on 04/06/2015). [20] Fabian Gerold. IfcPlusPlusExtender. url: http://www.ifcplusplus.com/extender.php (visited on 04/06/2015). [21] IFCPlusPlus2. url: https://github.com/VTREEM/IFCPlusPlus2 (visited on 04/06/2015). [22] Carve. url: http://carve-csg.com (visited on 04/06/2015). [23] OpenSceneGraph. url: http://www.openscenegraph.org (visited on 04/06/2015).

31 BIBLIOGRAPHY

[24] Avi Bar-Zeev. Scenegraphs: Past, Present, and Future. 2012. url: http://www.realityprime.com/blog/2007/06/scenegraphs- past-present-and-future/ (visited on 04/06/2015). [25] The Qt Company. Qt Application Development. url: http://www.qt.io/application-development/ (visited on 04/06/2015). [26] The Qt Company. Qt Widgets. url: http://doc.qt.io/qt-5/qtwidgets-index.html (visited on 04/06/2015). [27] Apple iPhone 5C Technical Specifications. url: http://trac.openscenegraph.org/documentation/ OpenSceneGraphReferenceDocs/a01012.html (visited on 04/08/2015). [28] Boost. url: http://www.boost.org (visited on 04/09/2015). [29] OpenMP. url: http://openmp.org/wp/ (visited on 04/06/2015). [30] osgViewer::Viewer Class Reference. url: http://trac.openscenegraph.org/documentation/ OpenSceneGraphReferenceDocs/a01012.html (visited on 04/06/2015). [31] Apple Inc. Blocks Programming Topics. 2011. url: https: //developer.apple.com/library/mac/documentation/ Cocoa/Conceptual/Blocks/Articles/00_Introduction.html (visited on 11/15/2015). [32] osgUtil::Optimizer Class Reference. url: http://trac.openscenegraph.org/documentation/ OpenSceneGraphReferenceDocs/a00554.html (visited on 04/06/2015). [33] Rui Wang and Xuelei Qian. OpenSceneGraph 3.0: Beginner’s Guide. Packt Publishing, 2010. isbn: 1849512825. url: http://www.amazon.com/OpenSceneGraph-3-0- Beginners-Rui-Wang/dp/1849512825.

32 BIBLIOGRAPHY

[34] Open IFC Model Repository of The University of Auckland. url: http://openifcmodel.cs.auckland.ac.nz/Model (visited on 04/13/2015). [35] Jing Sun et al. “IFCCompressor: A content-based compression algorithm for optimizing Industry Foundation Classes files”. In: Automation in Construction 50 (2015), pp. 1–15. url: http://cgcad.thss.tsinghua.edu.cn/liuyushen/ IFCCompressor/index.html (visited on 11/13/2015). [36] Architect Building Designer Office. KIT: AC11-Institute-Var-2-IFC | KIT: AC1-001. July 3, 2008. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/110 (visited on 04/13/2015). [37] Architect Building Designer Office. KIT: AC-11-Smiley-West-04-07-2007 | KIT: AC–001. July 5, 2007. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/111 (visited on 04/13/2015). [38] BLIS Certification Team BLIS. BLIS: 23_IFCR2_Buildings_2 | BLIS: 23-001. May 22, 2001. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/108 (visited on 04/13/2015). [39] klaus Organization. KIT: FZK-Haus-EliteCAD | KIT: FZK-001. June 20, 2008. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/124 (visited on 04/13/2015). [40] Franz-Josef Kaiser, A. Knoll, and Herxheim. KIT: FJK-Project-Final | KIT: FJK-001. Nov. 30, 2010. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/123 (visited on 04/13/2015). [41] Karl-Heinz Haefele. KIT: Ettenheim-GIS-05-11-2006_optimized | KIT: Ett-001. Nov. 9, 2006. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/119 (visited on 04/13/2015).

33 BIBLIOGRAPHY

[42] Karl-Heinz Haefele. KIT: Ettenheim-GIS-05-11-2006 | KIT: Ett-001. Nov. 9, 2006. url: http: //openifcmodel.cs.auckland.ac.nz/Model/Details/118 (visited on 04/13/2015). [43] Jing Sun et al. IFCCompressor – M1 Test Case. Mar. 19, 2013. url: http://cgcad.thss.tsinghua.edu.cn/liuyushen/ IFCCompressor/ifc/M1.ifc (visited on 04/13/2015). [44] Joe Conway, Aaron Hillegass, and Christian Keur. iOS Programming: The Big Nerd Ranch Guide (4th Edition) (Big Nerd Ranch Guides). Big Nerd Ranch Guides, 2014. isbn: 0321942051. url: http://www.amazon.com/iOS- Programming-Ranch-Edition-Guides/dp/0321942051.

34 A Test Models

(a) M1 [36] (b) M2 [37] (c) M3 [38]

(d) M4 [39] (e) M5 [40] (f) M6 [41], M7 [42]

35 A. Test Models

Figure A.2: List of test models displayed in FileListTableViewController.A deletion of a model copied from other application is depicted.

36 B MultiTouchOrbit3DManipulator Source Code Example

// // MultiTouchOrbit3DManipulator.cpp // Viewer // // Created by Martin Skrovina on 5/3/15. // Copyright (c) 2015 skrovina. All rights reserved. //

#include "MultiTouchOrbit3DManipulator.h"

#include #include

MultiTouchOrbit3DManipulator::MultiTouchOrbit3DManipulator ( IfcPlusPlusSystem* sys, int flags ) : Orbit3DManipulator(sys, flags) { setVerticalAxisFixed( false ); }

/// Handles the multi-touch camera pan and zoom void MultiTouchOrbit3DManipulator:: handleMultiTouchGesture(osgGA::GUIEventAdapter::TouchData* now , osgGA::GUIEventAdapter::TouchData* last , const osgGA::GUIEventAdapter& ea , osgGA::GUIActionAdapter& aa , const double eventTimeDelta) { /// Multipliers for screen size independent manipulations osg::Vec2 screenCompensationMultipliers(ea.getXmax() - ea.getXmin() , ea.getYmax() - ea.getYmin()); // Computations were done relative to iPhone screen screenCompensationMultipliers /= 640;

37 B. MultiTouchOrbit3DManipulator Source Code Example

// Touch points normalized to [-1, 1] osg::Vec2 pt1Now(now->get(0).x,now->get(0).y); osg::Vec2 pt2Now(now->get(1).x,now->get(1).y); osg::Vec2 pt1Last(last->get(0).x,last->get(0).y); osg::Vec2 pt2Last(last->get(1).x,last->get(1).y);

// Centers of the touch points for determining the ray intersection osg::Vec2 pxCenterPointLast = (pt1Last + pt2Last) / 2.; osg::Vec2 pxCenterPointNow = (pt1Now + pt2Now) / 2.; osg::Vec2 centerPointLast = normalizedScreenPoint( pxCenterPointLast, ea); osg::Vec2 centerPointNow = normalizedScreenPoint( pxCenterPointNow, ea);

// if any of the two fingers just begun, compute the ray pointer intersection if (last->get(0).phase == osgGA::GUIEventAdapter:: TOUCH_BEGAN || last->get(1).phase == osgGA::GUIEventAdapter:: TOUCH_BEGAN ){ // The y axis is flipped in the device screen coordinates computeRayPointer( ea, aa, osg::Vec2(centerPointLast.x (), -centerPointLast.y()) ); }

// compensate the vectors for different screen dimensions than the tested device std::vector< osg::Vec2 * > compensationVectors = { & pt1Now , & pt2Now , & pt1Last , & pt2Last , ¢erPointLast , ¢erPointNow }; for (auto vec : compensationVectors) { vec->x() *= screenCompensationMultipliers.x(); vec->y() *= screenCompensationMultipliers.y(); }

// compute sizes of gaps between fingers float gapNow((pt1Now - pt2Now).length());

38 B. MultiTouchOrbit3DManipulator Source Code Example float gapLast((pt1Last - pt2Last).length()); osg::Vec3 intersectionCameraVector = m_eye - m_rotate_center; float gapDifference = gapNow - gapLast;

// empirically reached factor constant float scrollDistanceFactor = intersectionCameraVector. length() * 0.1;

// zoom camera more the further it is from the ray intersection point zoomCamera(gapDifference * eventTimeDelta * scrollDistanceFactor);

// drag gesture osgViewer::View* view = dynamic_cast(& aa); if( ! view ) { return ; }

// move camera more the further it is from the ray intersection point osg::Vec2 distanceRatioPanFactors = screenCompensationMultipliers * fmax(0.8, intersectionCameraVector.length() * 0.2); osg::Vec2 dCenter = centerPointLast - centerPointNow;

// left camera vector is perpendicular to the camera up vector and the direction of camera osg::Vec3 left = m_up ^ (m_lookat - m_eye); // the m_up vector only defines camera 's roll but not its pitch // get the camera 's up direction vector osg::Vec3 camUp = left ^ (m_lookat - m_eye); camUp.normalize(); left.normalize(); osg::Vec3 leftShift = left * dCenter.x(); osg::Vec3 upShift = camUp * dCenter.y();

39 B. MultiTouchOrbit3DManipulator Source Code Example

leftShift *= distanceRatioPanFactors.x(); upShift *= distanceRatioPanFactors.y();

// translate the camera eye and lookat m_eye.set(m_eye -leftShift + upShift); m_lookat.set(m_lookat -leftShift + upShift);

return ; }

/// returns screen point normalized into interval [-1, 1] osg::Vec2 MultiTouchOrbit3DManipulator:: normalizedScreenPoint(osg::Vec2 point, const osgGA:: GUIEventAdapter& ea) { return ((osg::Vec2(point.x() / (ea.getXmax() - ea. getXmin()), point.y() / (ea.getYmax() - ea.getYmin()))) * 2.) - osg::Vec2(1., 1); } bool MultiTouchOrbit3DManipulator::handle( const osgGA:: GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) {

bool handled(false);

switch(ea.getEventType()) { case osgGA::GUIEventAdapter::PUSH: case osgGA::GUIEventAdapter::DRAG: case osgGA::GUIEventAdapter::RELEASE:

// Deselect the selected object and dismiss the menu if (this->selectionWasDismissedHandler) { this->selectionWasDismissedHandler(ea. getXnormalized(),ea.getYnormalized()); }

if (ea.isMultiTouchEvent()) { float eventTimeDelta = 1./60.; osgGA::GUIEventAdapter::TouchData* touchData = ea. getTouchData();

// Ensure the number of touches is at least 2, the others will be ignored if (touchData->getNumTouchPoints() >= 2) { if ((_lastTouchData.valid()) && (_lastTouchData

40 B. MultiTouchOrbit3DManipulator Source Code Example

->getNumTouchPoints() >= 2)) { handleMultiTouchGesture(touchData, _lastTouchData.get(), ea, aa, eventTimeDelta); } handled = true; }

_lastTouchData = touchData;

// check if all touches ended unsigned int num_touches_ended(0); for(osgGA::GUIEventAdapter::TouchData::iterator i = touchData->begin(); i != touchData->end(); ++i) { if ((*i).phase == osgGA::GUIEventAdapter:: TOUCH_ENDED){ num_touches_ended++; } }

if(num_touches_ended == touchData-> getNumTouchPoints()) { _lastTouchData = NULL; } } break ;

default : break ; }

// if the touches were not handled, call the superclass ' s implementation return handled ? handled : Orbit3DManipulator::handle(ea , aa); }

Listing B.1: MultiTouchOrbit3DManipulator

void Orbit3DManipulator::zoomCamera( const float dy ) { // push camera forward along mouse ray osg::Vec3d zoom_direction = m_ray_pointer_direction; zoom_direction.normalize();

41 B. MultiTouchOrbit3DManipulator Source Code Example

zoom_direction *= dy; m_eye += zoom_direction; m_lookat += zoom_direction; }

Listing B.2: Camera zoom

42