Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build directories
HW1/build/
HW2/build/
HW3/build/

# Compiled binaries
HW1/bin/
HW2/bin/
HW3/bin/

# CMake generated files
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
CTestTestfile.cmake
Testing/

# Static / shared libraries
*.a
*.so
*.so.*

# Editor / IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# macOS
.DS_Store
123 changes: 122 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,122 @@
# C-_tutorial
# C++ Tutorial — StachnissLab Homework Corrections

Solutions to all homework assignments of the **Modern C++ for Computer Vision
and Image Processing** course by Cyrill Stachniss
([StachnissLab](https://www.ipb.uni-bonn.de/), University of Bonn).

---

## Prerequisites

| Tool | Version |
|------|---------|
| C++ compiler | C++11 or later (g++ / clang++) |
| CMake | ≥ 3.1 |

---

## Repository structure

```
.
├── HW1/ # Homework 1 – Basic C++: string tokenisation & word frequency
├── HW2/ # Homework 2 – Greyscale image class with PGM file I/O
└── HW3/ # Homework 3 – Colour image class with Strategy-pattern I/O
```

---

## HW1 – String operations

**Topics covered:** `std::string`, `std::vector`, `std::map`, range-based for
loops, function design.

**Tasks:**
- `Tokenize(str, delimiter)` — splits a string into tokens using a delimiter
character, skipping empty tokens.
- `CountWordFrequency(str)` — counts how often each word appears in a string
and returns an alphabetically sorted list of `(word, count)` pairs.

### Build & run

```bash
cd HW1 && mkdir build && cd build
cmake ..
make
./bin/hw1_main
ctest --output-on-failure
```

---

## HW2 – Greyscale image class (`igg::Image`)

**Topics covered:** classes, const/non-const overloading, file I/O streams,
`std::vector`, histogram computation, image scaling.

**Class interface (`igg::Image`):**

| Method | Description |
|--------|-------------|
| `Image()` | Default constructor (empty image) |
| `Image(rows, cols)` | Constructor — creates a zero-filled image |
| `int rows() const` | Returns number of rows |
| `int cols() const` | Returns number of columns |
| `int& at(row, col)` | Pixel setter (returns mutable reference) |
| `const int& at(row, col) const` | Pixel getter (returns const reference) |
| `bool FillFromPgm(file)` | Reads an ASCII PGM (P2) file |
| `void WriteToPgm(file)` | Writes an ASCII PGM (P2) file |
| `vector<float> ComputeHistogram(bins)` | Computes pixel-count histogram |
| `void DownScale(scale)` | Sub-samples by keeping every `scale`-th pixel |
| `void UpScale(scale)` | Repeats each pixel `scale` times in both dimensions |

**Four demo applications** are provided in `src/application{1..4}/`:
1. Getter/setter demonstration
2. Read a PGM file, draw a diagonal, write it back
3. Compute and print a 10-bin histogram
4. Downscale and upscale a PGM image

### Build & run

```bash
cd HW2 && mkdir build && cd build
cmake ..
make
ctest --output-on-failure
```

---

## HW3 – Colour image class with Strategy pattern (`igg::Image`)

**Topics covered:** inheritance, virtual functions, abstract base classes,
the Strategy design pattern, colour images (RGB), PPM file format.

**Class hierarchy:**

```
IoStrategy (abstract base)
├── DummyIoStrategy (always succeeds write; returns empty on read — for tests)
└── PpmIoStrategy (plain PPM P3 format)
```

**`igg::Image` interface:**

| Method | Description |
|--------|-------------|
| `Image(strategy)` | Constructor — binds an I/O strategy |
| `Image(rows, cols, strategy)` | Constructor — creates a zero-filled image |
| `int rows() / int cols()` | Dimension accessors |
| `Pixel& at(row, col)` | Pixel accessor (read/write) |
| `const Pixel& at(row, col) const` | Pixel accessor (read-only) |
| `bool ReadFromDisk(file)` | Reads image via the strategy |
| `void WriteToDisk(file)` | Writes image via the strategy |

### Build & run

```bash
cd HW3 && mkdir build && cd build
cmake ..
make
ctest --output-on-failure
```
26 changes: 26 additions & 0 deletions homework_4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.14)
project(homework_4)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Fetch Catch2 v2
include(FetchContent)
FetchContent_Declare(
Catch2
URL https://github.com/catchorg/Catch2/releases/download/v2.13.9/catch.hpp
DOWNLOAD_NO_EXTRACT ON
)
FetchContent_GetProperties(Catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(Catch2)
file(COPY ${catch2_SOURCE_DIR}/catch.hpp DESTINATION ${CMAKE_BINARY_DIR}/include/catch2)
endif()

# Create interface library for ipb_algorithm
add_library(ipb_algorithm INTERFACE)
target_include_directories(ipb_algorithm INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Include tests
enable_testing()
add_subdirectory(tests)
106 changes: 106 additions & 0 deletions homework_4/build/DartConfiguration.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This file is configured by CMake automatically as DartConfiguration.tcl
# If you choose not to use CMake, this file may be hand configured, by
# filling in the required variables.


# Configuration directories and files
SourceDirectory: /home/franck-albert-fonkoua/C++_tutorials/homework_4
BuildDirectory: /home/franck-albert-fonkoua/C++_tutorials/homework_4/build

# Where to place the cost data store
CostDataFile:

# Site is something like machine.domain, i.e. pragmatic.crd
Site: franck-albert-fonkoua-IdeaPad-Pro-5-14ARP8

# Build name is osname-revision-compiler, i.e. Linux-2.4.2-2smp-c++
BuildName: Linux-c++

# Subprojects
LabelsForSubprojects:

# Submission information
SubmitURL: http://
SubmitInactivityTimeout:

# Dashboard start time
NightlyStartTime: 00:00:00 EDT

# Commands for the build/test/submit cycle
ConfigureCommand: "/usr/bin/cmake" "/home/franck-albert-fonkoua/C++_tutorials/homework_4"
MakeCommand: /usr/bin/cmake --build . --config "${CTEST_CONFIGURATION_TYPE}"
DefaultCTestConfigurationType: Release

# version control
UpdateVersionOnly:

# CVS options
# Default is "-d -P -A"
CVSCommand:
CVSUpdateOptions:

# Subversion options
SVNCommand:
SVNOptions:
SVNUpdateOptions:

# Git options
GITCommand:
GITInitSubmodules:
GITUpdateOptions:
GITUpdateCustom:

# Perforce options
P4Command:
P4Client:
P4Options:
P4UpdateOptions:
P4UpdateCustom:

# Generic update command
UpdateCommand:
UpdateOptions:
UpdateType:

# Compiler info
Compiler: /usr/lib/ccache/c++
CompilerVersion: 13.3.0

# Dynamic analysis (MemCheck)
PurifyCommand:
ValgrindCommand:
ValgrindCommandOptions:
DrMemoryCommand:
DrMemoryCommandOptions:
CudaSanitizerCommand:
CudaSanitizerCommandOptions:
MemoryCheckType:
MemoryCheckSanitizerOptions:
MemoryCheckCommand: /usr/bin/valgrind
MemoryCheckCommandOptions:
MemoryCheckSuppressionFile:

# Coverage
CoverageCommand: /usr/bin/gcov
CoverageExtraFlags: -l

# Testing options
# TimeOut is the amount of time in seconds to wait for processes
# to complete during testing. After TimeOut seconds, the
# process will be summarily terminated.
# Currently set to 25 minutes
TimeOut: 1500

# During parallel testing CTest will not start a new test if doing
# so would cause the system load to exceed this value.
TestLoad:

UseLaunchers:
CurlOptions:
# warning, if you add new options here that have to do with submit,
# you have to update cmCTestSubmitCommand.cxx

# For CTest submissions that timeout, these options
# specify behavior for retrying the submission
CTestSubmitRetryDelay: 5
CTestSubmitRetryCount: 3
Loading